Skip to content

Commit eda2a68

Browse files
authored
Use new NVD API v2 (#91)
* Update nvdlib and use NVD API v2 * Use delay recommended for NVD API requests * Run black formatter on source * Fix README.md
1 parent 332c06e commit eda2a68

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
This repo is used to
44

55
1. Run automated checks for vulnerabilities in Node.js dependencies that have
6-
already been made public
7-
1. Track and communicate information about vulnerabilities in depdencies that
8-
are public and have not yet been addressed. This maybe be to documented
9-
that they don't affect Node.js or what action is being taken to address
10-
then.
6+
already been made public.
7+
2. Track and communicate information about dependency vulnerabilities that
8+
are public and have not yet been addressed.
119

1210

1311
Automated checks are currently run through a GitHub action using
14-
[dep_checker](https://github.com/nodejs/node/tree/main/tools/dep_checker).
12+
[dep_checker](https://github.com/nodejs/nodejs-dependency-vuln-assessments/tree/main/dep_checker).
1513

16-
**DO NOT REPORT OR DISCUSS VULNERABLITIES THAT ARE NOT ALREADY
14+
**DO NOT REPORT OR DISCUSS VULNERABILITIES THAT ARE NOT ALREADY
1715
PUBLIC IN THIS REPO**. Please report new vulnerabilities either to
1816
the projects for a specific dependency or report to the Node.js project
19-
as outlined in the Node.js project's
17+
as outlined in the Node.js
2018
[SECURITY.md](https://github.com/nodejs/node/blob/main/SECURITY.md) file.
2119

2220

dep_checker/main.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"""
1313

1414
from argparse import ArgumentParser
15-
from collections import defaultdict
1615
from dependencies import (
1716
ignore_list,
1817
dependencies_info,
@@ -40,7 +39,12 @@ def __init__(self, id: str, url: str, dependency: str, version: str):
4039
class VulnerabilityEncoder(json.JSONEncoder):
4140
def default(self, obj):
4241
if isinstance(obj, Vulnerability):
43-
return {"id": obj.id, "url": obj.url, "dependency": obj.dependency, "version": obj.version}
42+
return {
43+
"id": obj.id,
44+
"url": obj.url,
45+
"dependency": obj.dependency,
46+
"version": obj.version,
47+
}
4448
# Let the base class default method raise the TypeError
4549
return json.JSONEncoder.default(self, obj)
4650

@@ -118,7 +122,10 @@ def query_ghad(
118122
found_vulnerabilities.extend(
119123
[
120124
Vulnerability(
121-
id=vuln["advisory"]["ghsaId"], url=vuln["advisory"]["permalink"], dependency=name, version=dep_version
125+
id=vuln["advisory"]["ghsaId"],
126+
url=vuln["advisory"]["permalink"],
127+
dependency=name,
128+
version=dep_version,
122129
)
123130
for vuln in matching_vulns
124131
]
@@ -146,14 +153,22 @@ def query_nvd(
146153
query_results = [
147154
cve
148155
for cve in searchCVE(
149-
cpeMatchString=dep.get_cpe(repo_path), keyword=dep.keyword, key=api_key
156+
virtualMatchString=dep.get_cpe(repo_path),
157+
keywordSearch=dep.keyword,
158+
key=api_key,
159+
delay=6 if api_key else False,
150160
)
151161
if cve.id not in ignore_list
152162
]
153163
if query_results:
154164
version = dep.version_parser(repo_path)
155165
found_vulnerabilities.extend(
156-
[Vulnerability(id=cve.id, url=cve.url, dependency=name, version=version) for cve in query_results]
166+
[
167+
Vulnerability(
168+
id=cve.id, url=cve.url, dependency=name, version=version
169+
)
170+
for cve in query_results
171+
]
157172
)
158173

159174
return found_vulnerabilities
@@ -185,7 +200,7 @@ def main() -> int:
185200
)
186201
parser.add_argument(
187202
"--json-output",
188-
action='store_true',
203+
action="store_true",
189204
help="the NVD API key for querying the National Vulnerability Database",
190205
)
191206
repo_path: Path = parser.parse_args().node_repo_path
@@ -216,13 +231,15 @@ def main() -> int:
216231
if name in dependencies_per_branch[repo_branch]
217232
}
218233
ghad_vulnerabilities: list[Vulnerability] = (
219-
{} if gh_token is None else query_ghad(dependencies, gh_token, repo_path)
234+
list() if gh_token is None else query_ghad(dependencies, gh_token, repo_path)
220235
)
221236
nvd_vulnerabilities: list[Vulnerability] = query_nvd(
222237
dependencies, nvd_key, repo_path
223238
)
224239

225-
all_vulnerabilities = {"vulnerabilities": ghad_vulnerabilities + nvd_vulnerabilities}
240+
all_vulnerabilities = {
241+
"vulnerabilities": ghad_vulnerabilities + nvd_vulnerabilities
242+
}
226243
no_vulnerabilities_found = not ghad_vulnerabilities and not nvd_vulnerabilities
227244
if json_output:
228245
print(json.dumps(all_vulnerabilities, cls=VulnerabilityEncoder))

dep_checker/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
gql[aiohttp]
2-
nvdlib==0.6.0
2+
nvdlib==0.7.0
33
packaging

0 commit comments

Comments
 (0)