Skip to content

Commit 7112e62

Browse files
adamtimminsTimmins, Adam
andauthored
Checkmarx one SCA parser fix (DefectDojo#10770)
* fixing CWE issue * adding weird findings to unit test * modifying the unit test to include the weird findings I'm seeing * restoring file to original state * creating new file for new unit test * add new unit test function merge conflict * switch to recommended file name * scan report name change * adding encoding * double quoutes --------- Co-authored-by: Timmins, Adam <[email protected]>
1 parent 2a98276 commit 7112e62

File tree

3 files changed

+720
-11
lines changed

3 files changed

+720
-11
lines changed

dojo/tools/checkmarx_one/parser.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22
import json
3+
import re
34
from typing import List
45

56
from dateutil import parser
@@ -26,6 +27,18 @@ def _parse_date(self, value):
2627
else:
2728
return None
2829

30+
def _parse_cwe(self, cwe):
31+
if isinstance(cwe, str):
32+
cwe_num = re.findall(r"\d+", cwe)
33+
if cwe_num:
34+
return cwe_num[0]
35+
else:
36+
return None
37+
elif isinstance(cwe, int):
38+
return cwe
39+
else:
40+
return None
41+
2942
def parse_vulnerabilities_from_scan_list(
3043
self,
3144
test: Test,
@@ -229,7 +242,7 @@ def parse_results(
229242
for vulnerability in results:
230243
result_type = vulnerability.get("type")
231244
date = self._parse_date(vulnerability.get("firstFoundAt"))
232-
cwe = vulnerability.get("vulnerabilityDetails", {}).get("cweId", None)
245+
cwe = self._parse_cwe(vulnerability.get("vulnerabilityDetails", {}).get("cweId", None))
233246
finding = None
234247
if result_type == "sast":
235248
finding = self.get_results_sast(test, vulnerability)

0 commit comments

Comments
 (0)