@@ -92,7 +92,7 @@ def get_scan_types(self):
92
92
return ["Mayhem SARIF Report" ]
93
93
94
94
def get_label_for_scan_types (self , scan_type ):
95
- return scan_type
95
+ return scan_type
96
96
97
97
def get_description_for_scan_types (self , scan_type ):
98
98
return "Mayhem SARIF reports from code or API runs."
@@ -189,6 +189,7 @@ def get_result_cwes_properties(result):
189
189
search_cwe (value , cwes )
190
190
return cwes
191
191
192
+
192
193
def get_result_cwes_mcode (result ):
193
194
"""Mayhem SARIF reports include CWE property under taxa.toolComponent.name and number under taxa.id"""
194
195
cwes = []
@@ -207,29 +208,28 @@ def get_artifacts(run):
207
208
artifacts [tree_artifact .get ("index" , custom_index )] = tree_artifact
208
209
return artifacts
209
210
211
+
210
212
def clean_mayhem_title_text (text ):
211
- """
212
- Clean the title text for Mayhem SARIF reports.
213
- """
213
+ """Clean the title text for Mayhem SARIF reports."""
214
214
if not text :
215
215
return ""
216
-
216
+
217
217
# Remove links (and add limit to avoid catastrophic backtracking)
218
218
link_regex = r"\[[^\]]{1,100}?\]\([^)]{1,200}?\)"
219
219
text = re .sub (link_regex , "" , text )
220
-
220
+
221
221
# Remove URL encoded characters
222
222
url_encoding_regex = r"&#x\d+;"
223
223
text = re .sub (url_encoding_regex , "" , text )
224
-
224
+
225
225
# Remove single or double quotes
226
226
quotes_regex = r"[\"']"
227
227
text = re .sub (quotes_regex , "" , text )
228
228
229
229
# Remove TDID
230
230
tdid_regex = r"TDID-\d+\s*-\s*|TDID-\d+-"
231
231
text = re .sub (tdid_regex , "" , text )
232
-
232
+
233
233
return text .strip ()
234
234
235
235
@@ -239,19 +239,19 @@ def get_message_from_multiformatMessageString(data, rule, content_type="text"):
239
239
240
240
See here for the specification: https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317468
241
241
"""
242
- if content_type not in [ "text" , "markdown" ] :
243
- raise ValueError (f "Unexpected content type: { content_type } " )
242
+ if content_type not in { "text" , "markdown" } :
243
+ raise ValueError ("Unexpected message content; expected 'text' or 'markdown'. " )
244
244
if content_type == "markdown" and "markdown" in data :
245
245
# handle markdown content
246
246
markdown = data .get ("markdown" )
247
247
# strip "headings" or anything that changes text size
248
248
heading_regex = r"^#+\s*"
249
249
markdown = re .sub (heading_regex , "" , markdown , flags = re .MULTILINE )
250
250
# replace non-unicode characters with "?"
251
- non_unicode_regex = r' [^\x09\x0A\x0D\x20-\x7E]'
252
- markdown = re .sub (non_unicode_regex , '?' , markdown )
251
+ non_unicode_regex = r" [^\x09\x0A\x0D\x20-\x7E]"
252
+ markdown = re .sub (non_unicode_regex , "?" , markdown )
253
253
return markdown .strip ()
254
- elif content_type == "text" and "text" in data :
254
+ if content_type == "text" and "text" in data :
255
255
# handle text content
256
256
text = data .get ("text" )
257
257
if rule is not None and "id" in data :
@@ -266,6 +266,7 @@ def get_message_from_multiformatMessageString(data, rule, content_type="text"):
266
266
else :
267
267
return ""
268
268
269
+
269
270
def cve_try (val ):
270
271
# Match only the first CVE!
271
272
cveSearch = re .search (r"(CVE-[0-9]+-[0-9]+)" , val , re .IGNORECASE )
@@ -297,7 +298,7 @@ def get_title(result, rule):
297
298
if title is None :
298
299
msg = "No information found to create a title"
299
300
raise ValueError (msg )
300
-
301
+
301
302
# Clean the title text for Mayhem SARIF reports
302
303
title = clean_mayhem_title_text (title )
303
304
@@ -374,7 +375,8 @@ def get_codeFlowsDescription(code_flows):
374
375
375
376
description += f"\t { message } \n "
376
377
377
- return description
378
+ return description
379
+
378
380
379
381
def get_description (result , rule , location ):
380
382
description = ""
@@ -400,10 +402,7 @@ def get_description(result, rule, location):
400
402
fullDescription = get_message_from_multiformatMessageString (
401
403
rule ["fullDescription" ], rule ,
402
404
)
403
- if (
404
- fullDescription != message
405
- and fullDescription != shortDescription
406
- ):
405
+ if (fullDescription != message ) and (fullDescription != shortDescription ):
407
406
description += f"**{ _ ('Rule full description' )} :** { fullDescription } \n "
408
407
if "markdown" in result ["message" ]:
409
408
markdown = get_message_from_multiformatMessageString (
@@ -412,7 +411,7 @@ def get_description(result, rule, location):
412
411
# Replace "Details" with "Link" in the markdown
413
412
markdown = markdown .replace ("Details" , "Link" )
414
413
description += f"**{ _ ('Additional Details' )} :**\n { markdown } \n "
415
- description += f "_(Unprintable characters are replaced with '?'; please see Mayhem for full reproducer.)_"
414
+ description += "_(Unprintable characters are replaced with '?'; please see Mayhem for full reproducer.)_"
416
415
if len (result .get ("codeFlows" , [])) > 0 :
417
416
description += get_codeFlowsDescription (result ["codeFlows" ])
418
417
0 commit comments