Skip to content

Commit 2d285cb

Browse files
🐛 fix npm audit v7+, issue #10801 (#10813)
1 parent 9c23523 commit 2d285cb

3 files changed

Lines changed: 75 additions & 5 deletions

File tree

dojo/tools/npm_audit_7_plus/parser.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ def get_item(item_node, tree, test):
121121
elif item_node["via"] and isinstance(item_node["via"][0], dict):
122122
title = item_node["via"][0]["title"]
123123
component_name = item_node["nodes"][0]
124-
cwe = item_node["via"][0]["cwe"][0]
124+
if len(item_node["via"][0]["cwe"]) > 0:
125+
cwe = item_node["via"][0]["cwe"][0]
126+
else:
127+
cwe = None
125128
references.append(item_node["via"][0]["url"])
126129
unique_id_from_tool = str(item_node["via"][0]["source"])
127130
cvssv3 = item_node["via"][0]["cvss"]["vectorString"]
@@ -144,15 +147,11 @@ def get_item(item_node, tree, test):
144147
if isinstance(vuln, dict):
145148
references.append(vuln["url"])
146149

147-
if len(cwe):
148-
cwe = int(cwe.split("-")[1])
149-
150150
dojo_finding = Finding(
151151
title=title,
152152
test=test,
153153
severity=severity,
154154
description=description,
155-
cwe=cwe,
156155
mitigation=mitigation,
157156
references=", ".join(references),
158157
component_name=component_name,
@@ -166,6 +165,10 @@ def get_item(item_node, tree, test):
166165
vuln_id_from_tool=unique_id_from_tool,
167166
)
168167

168+
if cwe is not None:
169+
cwe = int(cwe.split("-")[1])
170+
dojo_finding.cwe = cwe
171+
169172
if (cvssv3 is not None) and (len(cvssv3) > 0):
170173
dojo_finding.cvssv3 = cvssv3
171174

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"auditReportVersion": 2,
3+
"vulnerabilities": {
4+
"got": {
5+
"name": "got",
6+
"severity": "moderate",
7+
"isDirect": false,
8+
"via": [
9+
{
10+
"source": 1088948,
11+
"name": "got",
12+
"dependency": "got",
13+
"title": "Got allows a redirect to a UNIX socket",
14+
"url": "https://github.com/advisories/GHSA-pfrx-2q88-qq97",
15+
"severity": "moderate",
16+
"cwe": [],
17+
"cvss": {
18+
"score": 5.3,
19+
"vectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N"
20+
},
21+
"range": "<11.8.5"
22+
}
23+
],
24+
"effects": [
25+
],
26+
"range": "<11.8.5",
27+
"nodes": [
28+
"node_modules/got"
29+
],
30+
"fixAvailable": {
31+
"name": "nodemon",
32+
"version": "3.1.4",
33+
"isSemVerMajor": true
34+
}
35+
}
36+
},
37+
"metadata": {
38+
"vulnerabilities": {
39+
"info": 0,
40+
"low": 0,
41+
"moderate": 0,
42+
"high": 1,
43+
"critical": 0,
44+
"total": 1
45+
},
46+
"dependencies": {
47+
"prod": 98,
48+
"dev": 0,
49+
"optional": 0,
50+
"peer": 0,
51+
"peerOptional": 0,
52+
"total": 97
53+
}
54+
}
55+
}
56+

unittests/tools/test_npm_audit_7_plus_parser.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,14 @@ def test_npm_audit_7_plus_parser_with_many_vuln_has_many_findings(self):
4040
self.assertIsNotNone(finding.description)
4141
self.assertGreater(len(finding.description), 0)
4242
self.assertEqual("@vercel/fun", finding.title)
43+
44+
def test_npm_audit_7_plus_parser_issue_10801(self):
45+
testfile = open(path.join(path.dirname(__file__), "../scans/npm_audit_7_plus/issue_10801.json"))
46+
parser = NpmAudit7PlusParser()
47+
findings = parser.get_findings(testfile, Test())
48+
testfile.close()
49+
self.assertEqual(1, len(findings))
50+
with self.subTest(i=0):
51+
finding = findings[0]
52+
self.assertEqual("Medium", finding.severity)
53+
self.assertEqual(0, finding.cwe)

0 commit comments

Comments
 (0)