2424 DISK_LOCATION_BACKUP ,
2525 DISK_LOCATION_DEFAULT ,
2626 NVD_FILENAME_TEMPLATE ,
27+ NVD_VERSION ,
2728)
2829from cve_bin_tool .error_handler import (
2930 AttemptedToWriteOutsideCachedir ,
@@ -49,11 +50,13 @@ class NVD_Source(Data_Source):
4950 CACHEDIR = DISK_LOCATION_DEFAULT
5051 BACKUPCACHEDIR = DISK_LOCATION_BACKUP
5152 FEED_NVD = "https://nvd.nist.gov/vuln/data-feeds"
52- FEED_MIRROR = "https://v4.mirror.cveb.in/nvd/json/cve/1.1 "
53+ FEED_MIRROR = f "https://v4.mirror.cveb.in/nvd/json/cve/{ NVD_VERSION } "
5354 LOGGER = LOGGER .getChild ("CVEDB" )
5455 NVDCVE_FILENAME_TEMPLATE = NVD_FILENAME_TEMPLATE
56+ NVDCVE_VERSION = NVD_VERSION
57+ NVDCVE_TOP_LIST_TAG = "CVE_Items" if NVD_VERSION == "1.1" else "vulnerabilities"
5558 META_LINK_NVD = "https://nvd.nist.gov"
56- META_LINK_MIRROR = "https://v4.mirror.cveb.in/nvd/json/cve/1.1 "
59+ META_LINK_MIRROR = f "https://v4.mirror.cveb.in/nvd/json/cve/{ NVD_VERSION } "
5760 META_REGEX_NVD = re .compile (r"feeds\/json\/.*-[0-9]*\.[0-9]*-[0-9]*\.meta" )
5861 META_REGEX_MIRROR = re .compile (r"nvdcve-[0-9]*\.[0-9]*-[0-9]*\.meta" )
5962 RANGE_UNSET = ""
@@ -107,9 +110,14 @@ async def get_cve_data(self):
107110 severity_data = []
108111 affected_data = []
109112 years = self .nvd_years ()
113+ formatter = (
114+ self .format_data
115+ if self .NVDCVE_VERSION == "1.1"
116+ else self .format_data_api2
117+ )
110118 for year in years :
111- severity , affected = self . format_data (
112- self .load_nvd_year (year )["CVE_Items" ]
119+ severity , affected = formatter (
120+ self .load_nvd_year (year )[self . NVDCVE_TOP_LIST_TAG ]
113121 )
114122 severity_data .extend (severity )
115123 affected_data .extend (affected )
@@ -239,6 +247,10 @@ def format_data_api2(self, all_cve_entries):
239247
240248 cve_item = cve_element ["cve" ]
241249
250+ if cve_item ["vulnStatus" ] == "Rejected" :
251+ # Skip this CVE if it's marked as 'REJECT'
252+ continue
253+
242254 cve = {
243255 "ID" : cve_item ["id" ],
244256 "description" : cve_item ["descriptions" ][0 ]["value" ],
@@ -252,9 +264,6 @@ def format_data_api2(self, all_cve_entries):
252264 else cve_item ["published" ]
253265 ),
254266 }
255- if cve ["description" ].startswith ("** REJECT **" ):
256- # Skip this CVE if it's marked as 'REJECT'
257- continue
258267
259268 # Multiple ways of including CVSS metrics.
260269 # Newer data uses "impact" -- we may wish to delete the old below
@@ -612,17 +621,18 @@ def load_nvd_year(self, year: int) -> dict[str, str | object]:
612621 with gzip .open (filename , "rb" ) as fileobj :
613622 cves_for_year = json .load (fileobj )
614623 self .LOGGER .debug (
615- f' Year { year } has { len (cves_for_year ["CVE_Items" ])} CVEs in dataset'
624+ f" Year { year } has { len (cves_for_year [self . NVDCVE_TOP_LIST_TAG ])} CVEs in dataset"
616625 )
617626 return cves_for_year
618627
619628 def nvd_years (self ) -> list [int ]:
620629 """
621630 Return the years we have NVD data for.
622631 """
632+ any_year_file = self .NVDCVE_FILENAME_TEMPLATE .format ("*" )
623633 return sorted (
624634 int (filename .split ("." )[- 3 ].split ("-" )[- 1 ])
625- for filename in glob .glob (str (Path (self .cachedir ) / "nvdcve-1.1-*.json.gz" ))
635+ for filename in glob .glob (str (Path (self .cachedir ) / any_year_file ))
626636 )
627637 # FIXME: temporary workaround so we don't try to load bad year data
628638 # return list(range(2020, 2025))
0 commit comments