Skip to content

Commit 18b7c7f

Browse files
sysdig: fix severity mapping (#12873)
1 parent 2684481 commit 18b7c7f

9 files changed

Lines changed: 55 additions & 15 deletions

File tree

dojo/tools/sysdig_cli/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def parse_json(self, data, test):
6464
for item in vulns:
6565
# print("item: %s" % item)
6666
vulnName = item.get("name", "")
67-
vulnSeverity = item.get("severity", {}).get("value", "")
67+
vulnSeverity = SysdigData._map_severity(item.get("severity", {}).get("value", ""))
6868
vulnCvssScore = item.get("cvssScore", {}).get("value", {}).get("score", "")
6969
vulnCvssVersion = item.get("cvssScore", {}).get("value", {}).get("version", "")
7070
vulnCvssVector = item.get("cvssScore", {}).get("value", {}).get("vector", "")
@@ -130,7 +130,7 @@ def parse_csv(self, arr_data, test):
130130
finding.vuln_id_from_tool = row.vulnerability_id
131131
finding.unsaved_vulnerability_ids = []
132132
finding.unsaved_vulnerability_ids.append(row.vulnerability_id)
133-
finding.severity = row.severity
133+
finding.severity = SysdigData._map_severity(row.severity)
134134
# Set Component Version
135135
finding.component_name = row.package_name
136136
finding.component_version = row.package_version
@@ -221,7 +221,7 @@ def load_csv(self, filename) -> SysdigData:
221221
msg = ""
222222
# Sydig CLI format
223223
csv_data_record.vulnerability_id = row.get("cve id", "")
224-
csv_data_record.severity = csv_data_record._map_severity(row.get("cve severity").upper())
224+
csv_data_record.severity = SysdigData._map_severity(row.get("cve severity").upper())
225225
csv_data_record.cvss_score = row.get("cvss score", "")
226226
csv_data_record.cvss_version = row.get("cvss score version", "")
227227
csv_data_record.package_name = row.get("package name", "")

dojo/tools/sysdig_common/sysdig_data.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
class SysdigData:
88

9-
def _map_severity(self, severity):
9+
@classmethod
10+
def _map_severity(cls, severity):
1011
severity_mapping = {
1112
"CRITICAL": "Critical",
1213
"HIGH": "High",
@@ -15,7 +16,7 @@ def _map_severity(self, severity):
1516
"NEGLIGIBLE": "Informational",
1617
}
1718

18-
return severity_mapping.get(severity, "Informational")
19+
return severity_mapping.get(severity.upper() if severity else "", "Informational")
1920

2021
"""
2122
Data class to represent the Sysdig data extracted from sources like CSV or JSON.

dojo/tools/sysdig_reports/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def parse_json(self, data, test):
7373
k8sWorkloadName = item.get("k8sWorkloadName", "") or item.get("kubernetes_workload_name", "")
7474
k8sPodContainerName = item.get("k8sPodContainerName", "") or item.get("kubernetes_pod_container_name", "")
7575
vulnName = item.get("vulnName", "") or item.get("vuln_id", "")
76-
vulnSeverity = item.get("vulnSeverity", "") or item.get("vuln_severity", "")
76+
vulnSeverity = SysdigData._map_severity(item.get("vulnSeverity", "") or item.get("vuln_severity", ""))
7777
vulnLink = item.get("vulnLink", "") or "" # Not present in new format
7878
vulnCvssVersion = item.get("vulnCvssVersion", "") or item.get("vuln_cvss_version", "")
7979
vulnCvssScore = item.get("vulnCvssScore", "") or item.get("vuln_cvss_score", "")
@@ -294,7 +294,7 @@ def load_csv(self, filename) -> SysdigData:
294294
if "vulnerability id" in reader.fieldnames:
295295
# Old format: Vulnerability Engine Format
296296
csv_data_record.vulnerability_id = row.get("vulnerability id", "")
297-
csv_data_record.severity = csv_data_record._map_severity(row.get("severity", "").upper())
297+
csv_data_record.severity = SysdigData._map_severity(row.get("severity", "").upper())
298298
csv_data_record.package_name = row.get("package name", "")
299299
csv_data_record.package_version = row.get("package version", "")
300300
csv_data_record.package_type = row.get("package type", "")
@@ -329,7 +329,7 @@ def load_csv(self, filename) -> SysdigData:
329329
elif "vulnerability name" in reader.fieldnames:
330330
# New 2025 format
331331
csv_data_record.vulnerability_id = row.get("vulnerability name", "")
332-
csv_data_record.severity = csv_data_record._map_severity(row.get("vulnerability severity", "").upper())
332+
csv_data_record.severity = SysdigData._map_severity(row.get("vulnerability severity", "").upper())
333333
csv_data_record.package_name = row.get("package name", "")
334334
csv_data_record.package_version = row.get("package version", "")
335335
csv_data_record.package_type = row.get("package type", "")

unittests/scans/sysdig_cli/sysdig_reports_many_vul.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ CVE-2024-22195,Medium,6.1,3.1,Jinja2,2.11.2,/usr/local/lib/python2.7/dist-packag
2828
CVE-2024-34064,Medium,6.1,3.0,Jinja2,2.11.2,/usr/local/lib/python2.7/dist-packages/Jinja2-2.11.2.dist-info/METADATA,python,v3.1.5,,2024-01-11T00:00:00Z,2024-05-06T00:00:00Z,false,0.00044
2929
CVE-2014-1624,Low,3.3,2.0,pyxdg,0.25,/usr/share/pyshared/pyxdg-0.25.egg-info,python,v0.26.0,https://nvd.nist.gov/vuln/detail/CVE-2014-1624,2013-01-21T06:00:00Z,,false,0.00042
3030
CVE-2023-23934,Low,3.5,3.1,Werkzeug,1.0.1,/usr/local/lib/python2.7/dist-packages/Werkzeug-1.0.1.dist-info/METADATA,python,v2.1.1,https://nvd.nist.gov/vuln/detail/CVE-2023-23934,2023-02-14T00:00:00Z,2023-02-14T00:00:00Z,false,0.00064
31-
CVE-2023-5752,Low,3.3,3.1,pip,9.0.1,/usr/lib/python2.7/dist-packages/pip-9.0.1.egg-info/PKG-INFO,python,v19.2.0,https://nvd.nist.gov/vuln/detail/CVE-2023-5752,2023-10-01T00:00:00Z,2023-10-15T00:00:00Z,false,0.00048
32-
CVE-2024-49766,Low,3.7,3.0,Werkzeug,1.0.1,/usr/local/lib/python2.7/dist-packages/Werkzeug-1.0.1.dist-info/METADATA,python,v2.1.1,,2024-10-25T00:00:00Z,2024-10-25T00:00:00Z,false,0.00045
31+
CVE-2023-5752,Negligible,3.3,3.1,pip,9.0.1,/usr/lib/python2.7/dist-packages/pip-9.0.1.egg-info/PKG-INFO,python,v19.2.0,https://nvd.nist.gov/vuln/detail/CVE-2023-5752,2023-10-01T00:00:00Z,2023-10-15T00:00:00Z,false,0.00048
32+
CVE-2024-49766,Other,3.7,3.0,Werkzeug,1.0.1,/usr/local/lib/python2.7/dist-packages/Werkzeug-1.0.1.dist-info/METADATA,python,v2.1.1,,2024-10-25T00:00:00Z,2024-10-25T00:00:00Z,false,0.00045

unittests/scans/sysdig_cli/sysdig_reports_many_vul.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,7 +2687,7 @@
26872687
{
26882688
"name": "CVE-2024-49766",
26892689
"severity": {
2690-
"value": "Low",
2690+
"value": "Negligible",
26912691
"sourceName": "vulndb"
26922692
},
26932693
"cvssScore": {
@@ -2710,7 +2710,7 @@
27102710
{
27112711
"name": "CVE-2024-49767",
27122712
"severity": {
2713-
"value": "High",
2713+
"value": "Other",
27142714
"sourceName": "nvd"
27152715
},
27162716
"cvssScore": {

unittests/scans/sysdig_reports/sysdig-2025.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ CVE-2005-2541,Negligible,package name 1,0.0.0.1,OS,/path/path/file.abc,defectdoj
33
CVE-2005-2541,Negligible,package name 2,0.0.0.2,OS,/path/path/file.abc,defectdojo/defectdojo-django:latest,debian 12.9,2,10,AV:N/AC:L/Au:N/C:C/I:C/A:C,2005-08-10T04:00:00Z,1970-01-01T00:00:00Z,,false,k8s name 2,defectdojo,Deployment,defectdojo-django,uwsgi,sha256:a520752f350909c191db45a598a88fcca2fa5db17a340dee6b3d0e36f4122e11,false,false,,,,false
44
CVE-2005-2541,Negligible,package name 3,0.0.0.3,OS,/path/path/file.abc,docker.io/bitnami/redis:7.2.5-debian-12-r4,debian 12.6,2,10,AV:N/AC:L/Au:N/C:C/I:C/A:C,2005-08-10T04:00:00Z,1970-01-01T00:00:00Z,,false,k8s name 3,defectdojo,Deployment,defectdojo-redis-master,redis,sha256:a520752f350909c191db45a598a88fcca2fa5db17a340dee6b3d0e36f4122e11,false,false,,,,false
55
CVE-2025-48379,Critical,package name 4,0.0.0.4,Python,/path/path/path/file.abc,defectdojo/defectdojo-django:latest,debian 12.9,3,9.8,CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H,2025-07-01T17:29:37Z,2025-07-01T09:15:58Z,11.3.0,false,k8s name 4,defectdojo,Deployment,defectdojo-celery-beat,celery,sha256:a520752f350909c191db45a598a88fcca2fa5db17a340dee6b3d0e36f4122e11,true,false,,,,true
6-
CVE-2025-6021,Critical,package name 5,0.0.0.5,OS,/path/path/file.abc,defectdojo/defectdojo-django:latest,debian 12.9,3,9.8,CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H,2025-06-12T13:15:25Z,1970-01-01T00:00:00Z,,false,k8s name 5,defectdojo,Deployment,defectdojo-django,uwsgi,sha256:a520752f350909c191db45a598a88fcca2fa5db17a340dee6b3d0e36f4122e11,false,false,,,,false
7-
CVE-2011-10007,Critical,package name 6,0.0.0.6,OS,/path/path/file.abc,docker.io/bitnami/redis:7.2.5-debian-12-r4,debian 12.6,3,9.8,CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H,2025-06-05T12:15:22Z,1970-01-01T00:00:00Z,0.34-4~deb12u1,false,k8s name 6,defectdojo,Deployment,defectdojo-redis-master,redis,sha256:a520752f350909c191db45a598a88fcca2fa5db17a340dee6b3d0e36f4122e11,false,false,,,,true
6+
CVE-2025-6021,Negligible,package name 5,0.0.0.5,OS,/path/path/file.abc,defectdojo/defectdojo-django:latest,debian 12.9,3,9.8,CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H,2025-06-12T13:15:25Z,1970-01-01T00:00:00Z,,false,k8s name 5,defectdojo,Deployment,defectdojo-django,uwsgi,sha256:a520752f350909c191db45a598a88fcca2fa5db17a340dee6b3d0e36f4122e11,false,false,,,,false
7+
CVE-2011-10007,Other,package name 6,0.0.0.6,OS,/path/path/file.abc,docker.io/bitnami/redis:7.2.5-debian-12-r4,debian 12.6,3,9.8,CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H,2025-06-05T12:15:22Z,1970-01-01T00:00:00Z,0.34-4~deb12u1,false,k8s name 6,defectdojo,Deployment,defectdojo-redis-master,redis,sha256:a520752f350909c191db45a598a88fcca2fa5db17a340dee6b3d0e36f4122e11,false,false,,,,true

unittests/scans/sysdig_reports/sysdig-2025.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
"vuln_has_exploit": false,
184184
"vuln_id": "CVE-2025-48379",
185185
"vuln_risk_accepted": false,
186-
"vuln_severity": "Critical"
186+
"vuln_severity": "Other"
187187
},
188188
{
189189
"container_image": "defectdojo/defectdojo-django:latest",

unittests/tools/test_sysdig_cli_parser.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,19 @@ def test_sysdig_parser_with_many_vuln_has_many_findings_cli(self):
99
with (get_unit_tests_scans_path("sysdig_cli") / "sysdig_reports_many_vul.csv").open(encoding="utf-8") as testfile:
1010
parser = SysdigCLIParser()
1111
findings = parser.get_findings(testfile, Test())
12+
# Verify each CVE appears exactly once
13+
all_vuln_ids = [vid for f in findings for vid in f.unsaved_vulnerability_ids]
14+
self.assertEqual(1, all_vuln_ids.count("CVE-2023-5752"), "CVE-2023-5752 should appear exactly once")
15+
self.assertEqual(1, all_vuln_ids.count("CVE-2024-49766"), "CVE-2024-49766 should appear exactly once")
16+
1217
for finding in findings:
1318
for endpoint in finding.unsaved_endpoints:
1419
endpoint.clean()
20+
if "CVE-2023-5752" in finding.unsaved_vulnerability_ids:
21+
self.assertEqual(finding.severity, "Informational") # Negligible maps to Informational
22+
if "CVE-2024-49766" in finding.unsaved_vulnerability_ids:
23+
self.assertEqual(finding.severity, "Informational") # Other maps to Informational
24+
1525
self.assertEqual(31, len(findings))
1626
finding = findings[0]
1727
self.assertEqual("CVE-2013-7459 - pycrypto", finding.title)
@@ -27,9 +37,19 @@ def test_sysdig_parser_json_with_many_findings_cli(self):
2737
with (get_unit_tests_scans_path("sysdig_cli") / "sysdig_reports_many_vul.json").open(encoding="utf-8") as testfile:
2838
parser = SysdigCLIParser()
2939
findings = parser.get_findings(testfile, Test())
40+
# Verify each CVE appears exactly once
41+
all_vuln_ids = [vid for f in findings for vid in f.unsaved_vulnerability_ids]
42+
self.assertEqual(1, all_vuln_ids.count("CVE-2024-49766"), "CVE-2024-49766 should appear exactly once")
43+
self.assertEqual(1, all_vuln_ids.count("CVE-2024-49767"), "CVE-2024-49767 should appear exactly once")
44+
3045
for finding in findings:
3146
for endpoint in finding.unsaved_endpoints:
3247
endpoint.clean()
48+
if "CVE-2024-49766" in finding.unsaved_vulnerability_ids:
49+
self.assertEqual(finding.severity, "Informational") # Negligible maps to Informational
50+
if "CVE-2024-49767" in finding.unsaved_vulnerability_ids:
51+
self.assertEqual(finding.severity, "Informational") # Other maps to Informational
52+
3353
self.assertEqual(31, len(findings))
3454
finding = findings[0]
3555
self.assertEqual("CVE-2023-50782 - cryptography - v42.0.0", finding.title)

unittests/tools/test_sysdig_reports_parser.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,19 @@ def test_sysdig_parser_2025_csv_format(self):
8282
with (get_unit_tests_scans_path("sysdig_reports") / "sysdig-2025.csv").open(encoding="utf-8") as testfile:
8383
parser = SysdigReportsParser()
8484
findings = parser.get_findings(testfile, Test())
85+
# Verify each CVE appears exactly once
86+
all_vuln_ids = [vid for f in findings for vid in f.unsaved_vulnerability_ids]
87+
self.assertEqual(1, all_vuln_ids.count("CVE-2025-6021"), "CVE-2025-6021 should appear exactly once")
88+
self.assertEqual(1, all_vuln_ids.count("CVE-2011-10007"), "CVE-2011-10007 should appear exactly once")
8589
for finding in findings:
8690
for endpoint in finding.unsaved_endpoints:
8791
endpoint.clean()
92+
93+
if "CVE-2025-6021" in finding.unsaved_vulnerability_ids:
94+
self.assertEqual(finding.severity, "Informational") # Other maps to Informational
95+
if "CVE-2011-10007" in finding.unsaved_vulnerability_ids:
96+
self.assertEqual(finding.severity, "Informational") # Negligible maps to Informational
97+
8898
self.assertEqual(6, len(findings))
8999

90100
# Test specific finding details from the 2025 format
@@ -105,9 +115,18 @@ def test_sysdig_parser_2025_json_format(self):
105115
with (get_unit_tests_scans_path("sysdig_reports") / "sysdig-2025.json").open(encoding="utf-8") as testfile:
106116
parser = SysdigReportsParser()
107117
findings = parser.get_findings(testfile, Test())
118+
# Verify each CVE appears exactly once
119+
all_vuln_ids = [vid for f in findings for vid in f.unsaved_vulnerability_ids]
120+
self.assertEqual(1, all_vuln_ids.count("CVE-2023-45322"), "CVE-2023-45322 should appear exactly once")
121+
self.assertEqual(1, all_vuln_ids.count("CVE-2025-48379"), "CVE-2025-48379 should appear exactly once")
122+
108123
for finding in findings:
109124
for endpoint in finding.unsaved_endpoints:
110125
endpoint.clean()
126+
if "CVE-2023-45322" in finding.unsaved_vulnerability_ids:
127+
self.assertEqual(finding.severity, "Informational") # Negligible maps to Informational
128+
if "CVE-2025-48379" in finding.unsaved_vulnerability_ids:
129+
self.assertEqual(finding.severity, "Informational") # Other maps to Informational
111130

112131
# Should parse successfully even with metadata before data section
113132
self.assertGreater(len(findings), 0)

0 commit comments

Comments
 (0)