Skip to content

Commit 186befb

Browse files
🐛 fix nancy severity calculation #13656 (#13657)
1 parent 3396e7b commit 186befb

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

dojo/tools/nancy/parser.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,24 @@ def get_findings(self, scan_file, test):
3434

3535
return findings
3636

37+
def convert_cvss_score(self, raw_value):
38+
if raw_value is None:
39+
return "Info"
40+
val = float(raw_value)
41+
if val == 0.0:
42+
return "Info"
43+
if val < 4.0:
44+
return "Low"
45+
if val < 7.0:
46+
return "Medium"
47+
if val < 9.0:
48+
return "High"
49+
return "Critical"
50+
3751
def get_items(self, vulnerable, test):
3852
findings = []
3953
for vuln in vulnerable:
4054
finding = None
41-
severity = "Info"
42-
# the tool does not define severity, however it
43-
# provides CVSSv3 vector which will calculate
44-
# severity dynamically on save()
4555
references = []
4656
if vuln["Vulnerabilities"]:
4757
comp_name = vuln["Coordinates"].split(":")[1].split("@")[0]
@@ -57,7 +67,7 @@ def get_items(self, vulnerable, test):
5767
title=associated_vuln["Title"],
5868
description=associated_vuln["Description"],
5969
test=test,
60-
severity=severity,
70+
severity=self.convert_cvss_score(associated_vuln["CvssScore"]),
6171
component_name=comp_name,
6272
component_version=comp_version,
6373
false_p=False,

unittests/tools/test_nancy_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_nancy_parser_with_one_vuln_has_one_findings(self):
1818
self.assertEqual(1, len(findings))
1919
with self.subTest(i=0):
2020
finding = findings[0]
21-
self.assertEqual("Info", finding.severity)
21+
self.assertEqual("Medium", finding.severity)
2222
self.assertIsNotNone(finding.description)
2323
self.assertGreater(len(finding.description), 0)
2424
self.assertEqual(None, finding.cve)

0 commit comments

Comments
 (0)