|
1 | 1 | import hashlib |
2 | 2 | import json |
| 3 | +import logging |
3 | 4 |
|
4 | 5 | from dojo.models import Finding |
5 | 6 |
|
| 7 | +logger = logging.getLogger(__name__) |
| 8 | + |
6 | 9 | __author__ = "mwager" |
7 | 10 |
|
8 | 11 |
|
@@ -37,50 +40,59 @@ def get_findings(self, filename, test): |
37 | 40 | if row["muted"] is True: |
38 | 41 | continue |
39 | 42 |
|
40 | | - finding = Finding(test=test) |
41 | | - finding.unique_id_from_tool = row["id"] |
42 | | - finding.cve = row["cve"] |
43 | | - finding.description = row["description"] |
44 | | - finding.severity = self.SEVERITY[row["securityRisk"]] |
45 | | - |
46 | | - if "components" in row and len(row["components"]) > 0: |
47 | | - finding.component_name = row["components"][0]["artifact"] |
48 | | - finding.component_version = row["components"][0]["version"] |
49 | | - finding.title = finding.component_name + " v" + str(finding.component_version) |
50 | | - |
51 | | - if not finding.title: |
52 | | - finding.title = row["cve"] |
53 | | - |
54 | | - if "cwe" in row and "CWE-" in row["cwe"]: |
55 | | - finding.cwe = int(row["cwe"].replace("CWE-", "")) |
56 | | - |
57 | | - if "epss_score" in row: |
58 | | - finding.epss_score = row["epss_score"] |
59 | | - if "epss_percentile" in row: |
60 | | - finding.epss_percentile = row["epss_percentile"] |
61 | | - |
62 | | - if "cVSSv3BaseScore" in row: |
63 | | - finding.cvssv3_score = float(row["cVSSv3BaseScore"]) |
64 | | - |
65 | | - finding.references = "See Kiuwan Web UI" |
66 | | - finding.mitigation = "See Kiuwan Web UI" |
67 | | - finding.static_finding = True |
68 | | - |
69 | | - key = hashlib.sha256( |
70 | | - ( |
71 | | - finding.description |
72 | | - + "|" |
73 | | - + finding.severity |
74 | | - + "|" |
75 | | - + finding.component_name |
76 | | - + "|" |
77 | | - + finding.component_version |
78 | | - + "|" |
79 | | - + str(finding.cwe) |
80 | | - ).encode("utf-8"), |
81 | | - ).hexdigest() |
82 | | - |
83 | | - if key not in dupes: |
84 | | - dupes[key] = finding |
| 43 | + components = row.get("components", []) |
| 44 | + if not components: |
| 45 | + logger.debug("Insights Finding from Kiuwan does not have a related component - Skipping.") |
| 46 | + continue |
| 47 | + |
| 48 | + # We want one unique finding in DD for each component affected: |
| 49 | + for component in components: |
| 50 | + finding = Finding(test=test) |
| 51 | + finding.vuln_id_from_tool = str(row["id"]) |
| 52 | + finding.cve = row["cve"] |
| 53 | + finding.description = row["description"] |
| 54 | + finding.severity = self.SEVERITY[row["securityRisk"]] |
| 55 | + |
| 56 | + if "artifact" in component: |
| 57 | + finding.component_name = component["artifact"] |
| 58 | + if "version" in component: |
| 59 | + finding.component_version = component["version"] |
| 60 | + |
| 61 | + if finding.component_name and finding.component_version: |
| 62 | + finding.title = f"{finding.component_name} v{finding.component_version}" |
| 63 | + else: |
| 64 | + finding.title = finding.cve or "Unnamed Finding" |
| 65 | + |
| 66 | + if "cwe" in row and "CWE-" in row["cwe"]: |
| 67 | + finding.cwe = int(row["cwe"].replace("CWE-", "")) |
| 68 | + |
| 69 | + if "epss_score" in row: |
| 70 | + finding.epss_score = row["epss_score"] |
| 71 | + if "epss_percentile" in row: |
| 72 | + finding.epss_percentile = row["epss_percentile"] |
| 73 | + |
| 74 | + if "cVSSv3BaseScore" in row: |
| 75 | + finding.cvssv3_score = float(row["cVSSv3BaseScore"]) |
| 76 | + |
| 77 | + finding.references = "See Kiuwan Web UI" |
| 78 | + finding.mitigation = "See Kiuwan Web UI" |
| 79 | + finding.static_finding = True |
| 80 | + |
| 81 | + key = hashlib.sha256( |
| 82 | + ( |
| 83 | + finding.description |
| 84 | + + "|" |
| 85 | + + finding.severity |
| 86 | + + "|" |
| 87 | + + finding.component_name |
| 88 | + + "|" |
| 89 | + + finding.component_version |
| 90 | + + "|" |
| 91 | + + str(finding.cwe or "") |
| 92 | + ).encode("utf-8"), |
| 93 | + ).hexdigest() |
| 94 | + |
| 95 | + if key not in dupes: |
| 96 | + dupes[key] = finding |
85 | 97 |
|
86 | 98 | return list(dupes.values()) |
0 commit comments