1
1
package com .fortify .ssc .parser .sarif .parser ;
2
2
3
+ import java .util .Collections ;
4
+ import java .util .List ;
3
5
import java .util .Map ;
4
6
import java .util .TreeMap ;
7
+ import java .util .stream .Collectors ;
5
8
6
9
import org .apache .commons .codec .digest .DigestUtils ;
7
10
import org .apache .commons .lang3 .StringUtils ;
@@ -105,6 +108,7 @@ public final void produceVulnerability(RunData runData, Result result) {
105
108
vb .setStringCustomAttributeValue (CustomVulnAttribute .toolName , runData .getToolName ());
106
109
vb .setStringCustomAttributeValue (CustomVulnAttribute .help , getHelp (runData , result ));
107
110
vb .setStringCustomAttributeValue (CustomVulnAttribute .helpUri , getHelpUri (runData , result ));
111
+ vb .setStringCustomAttributeValue (CustomVulnAttribute .tags , getTags (runData , result ));
108
112
109
113
vb .completeVulnerability ();
110
114
}
@@ -268,6 +272,16 @@ private Priority getPriority(RunData runData, Result result) {
268
272
}
269
273
return result .resolveLevel (runData ).getFortifyPriority ();
270
274
}
275
+
276
+ private String getTags (RunData runData , Result result ) {
277
+ return getStringListProperty (getRuleProperties (runData , result ), "tags" , Collections .emptyList ())
278
+ .stream ()
279
+ // the tag "security" is almost always present for many SARIF reports because GitHub Code Scanning requires that tag be present for findings to appear
280
+ // See https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning
281
+ // Since it's not really useful, filter it out.
282
+ .filter (s -> ! "security" .equalsIgnoreCase (s ))
283
+ .collect (Collectors .joining (", " ));
284
+ }
271
285
272
286
private String getRuleGuid (RunData runData , Result result ) {
273
287
if ( isConvertedFromFortifyXml (runData ) ) {
@@ -278,7 +292,7 @@ private String getRuleGuid(RunData runData, Result result) {
278
292
return null ;
279
293
}
280
294
}
281
-
295
+
282
296
private String getCategoryAndSubCategory (RunData runData , Result result ) {
283
297
String category = getCategory (runData , result );
284
298
String subCategory = getSubCategory (runData , result );
@@ -304,6 +318,13 @@ private String getStringProperty(Map<String, Object> properties, String key, Str
304
318
return defaultValue ;
305
319
}
306
320
321
+ private List <String > getStringListProperty (Map <String , Object > properties , String key , List <String > defaultValue ) {
322
+ if ( properties !=null && properties .containsKey (key ) && properties .get (key ) instanceof List ) {
323
+ return (List <String >) properties .get (key );
324
+ }
325
+ return defaultValue ;
326
+ }
327
+
307
328
private Map <String , Object > getRuleProperties (ReportingDescriptor rule ) {
308
329
return rule ==null ? null : rule .getProperties ();
309
330
}
0 commit comments