Skip to content

Commit 0063e1c

Browse files
authored
manage not defined metadata in mitigations and add assumptions comments (#10897)
1 parent ab59763 commit 0063e1c

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

dojo/tools/threat_composer/parser.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ def get_findings(self, file, test):
7070

7171
if "threatAction" in threat:
7272
title = threat["threatAction"]
73-
severity, impact, comments = self.parse_threat_metadata(threat["metadata"])
73+
severity, impact, comments = self.parse_threat_metadata(threat.get("metadata", []))
7474
description = self.to_description_text(threat, comments, assumption_threat_links[threat["id"]])
7575
mitigation = self.to_mitigation_text(mitigation_links[threat["id"]])
7676
unique_id_from_tool = threat["id"]
7777
vuln_id_from_tool = threat["numericId"]
78-
tags = threat["tags"] if "tags" in threat else []
78+
tags = threat.get("tags", [])
7979

8080
finding = Finding(
8181
title=title,
@@ -112,14 +112,12 @@ def to_mitigation_text(self, mitigations):
112112
counti = i + 1
113113
text += f"**Mitigation {counti} (ID: {mitigation['numericId']}, Status: {mitigation.get('status', 'Not defined')})**: {mitigation['content']}"
114114

115-
for item in mitigation["metadata"]:
115+
for item in mitigation.get("metadata", []):
116116
if item["key"] == "Comments":
117117
text += f"\n*Comments*: {item['value'].replace(linesep, ' ')} "
118118
break
119119

120-
for j, assumption in enumerate(assumption_links):
121-
countj = j + 1
122-
text += f"\n- *Assumption {countj} (ID: {assumption['numericId']})*: {assumption['content'].replace(linesep, ' ')}"
120+
text += self.to_assumption_text(assumption_links)
123121

124122
text += "\n"
125123

@@ -145,8 +143,19 @@ def to_description_text(self, threat, comments, assumption_links):
145143
if comments:
146144
text += f"\n*Comments*: {comments}"
147145

146+
text += self.to_assumption_text(assumption_links)
147+
148+
return text
149+
150+
def to_assumption_text(self, assumption_links):
151+
text = ""
148152
for i, assumption in enumerate(assumption_links):
149153
counti = i + 1
150154
text += f"\n- *Assumption {counti} (ID: {assumption['numericId']})*: {assumption['content'].replace(linesep, ' ')}"
151155

156+
for item in assumption.get("metadata", []):
157+
if item["key"] == "Comments":
158+
text += f"\n  *Comments*: {item['value'].replace(linesep, ' ')} "
159+
break
160+
152161
return text

unittests/scans/threat_composer/threat_composer_many_threats.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,8 @@
9494
"tags": [
9595
"lorem ipsum"
9696
],
97-
"metadata": [
98-
{
99-
"key": "Comments",
100-
"value": "lorem ipsum"
101-
}
102-
],
103-
"displayOrder": 21
97+
"displayOrder": 21,
98+
"status": "mitigationResolved"
10499
},
105100
{
106101
"id": "11fb1c71-42f0-4004-89a7-09d8bf6f8b11",

0 commit comments

Comments
 (0)