Skip to content

Commit f57f3ac

Browse files
authored
feat: Display SARIF tags (#31)
1 parent 70b1a25 commit f57f3ac

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

src/main/java/com/fortify/ssc/parser/sarif/CustomVulnAttribute.java

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public enum CustomVulnAttribute implements com.fortify.plugin.spi.VulnerabilityA
3939
categoryAndSubCategory(AttrType.STRING),
4040
help(AttrType.LONG_STRING),
4141
helpUri(AttrType.STRING),
42+
tags(AttrType.LONG_STRING),
4243
;
4344

4445
private final AttrType attributeType;

src/main/java/com/fortify/ssc/parser/sarif/parser/VulnerabilitiesProducer.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.fortify.ssc.parser.sarif.parser;
22

3+
import java.util.Collections;
4+
import java.util.List;
35
import java.util.Map;
46
import java.util.TreeMap;
7+
import java.util.stream.Collectors;
58

69
import org.apache.commons.codec.digest.DigestUtils;
710
import org.apache.commons.lang3.StringUtils;
@@ -105,6 +108,7 @@ public final void produceVulnerability(RunData runData, Result result) {
105108
vb.setStringCustomAttributeValue(CustomVulnAttribute.toolName, runData.getToolName());
106109
vb.setStringCustomAttributeValue(CustomVulnAttribute.help, getHelp(runData, result));
107110
vb.setStringCustomAttributeValue(CustomVulnAttribute.helpUri, getHelpUri(runData, result));
111+
vb.setStringCustomAttributeValue(CustomVulnAttribute.tags, getTags(runData, result));
108112

109113
vb.completeVulnerability();
110114
}
@@ -268,6 +272,16 @@ private Priority getPriority(RunData runData, Result result) {
268272
}
269273
return result.resolveLevel(runData).getFortifyPriority();
270274
}
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+
}
271285

272286
private String getRuleGuid(RunData runData, Result result) {
273287
if ( isConvertedFromFortifyXml(runData) ) {
@@ -278,7 +292,7 @@ private String getRuleGuid(RunData runData, Result result) {
278292
return null;
279293
}
280294
}
281-
295+
282296
private String getCategoryAndSubCategory(RunData runData, Result result) {
283297
String category = getCategory(runData, result);
284298
String subCategory = getSubCategory(runData, result);
@@ -304,6 +318,13 @@ private String getStringProperty(Map<String, Object> properties, String key, Str
304318
return defaultValue;
305319
}
306320

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+
307328
private Map<String, Object> getRuleProperties(ReportingDescriptor rule) {
308329
return rule==null ? null : rule.getProperties();
309330
}

src/main/resources/plugin.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<plugin-info>
66
<name>SARIF parser plugin</name>
77
<version><!--VERSION-->0.0<!--/VERSION--></version>
8-
<data-version>2</data-version>
8+
<data-version>3</data-version>
99
<vendor name="Micro Focus" url="https://www.microfocus.com"/>
1010
<description>SARIF parser plugin</description>
1111
<resources>

src/main/resources/resources/sarif_en.properties

+1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ audited=Audited
2222
description=Description
2323
help=Help
2424
helpUri=More Info
25+
tags=Tags
2526
comment=Comment
2627
textBase64=Long text (base64 example)

src/main/resources/viewtemplate/ViewTemplate.json

+6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363
"key": "customAttributes.helpUri",
6464
"templateId": "SIMPLE",
6565
"dataType": "string"
66+
},
67+
{
68+
"type": "template",
69+
"key": "customAttributes.tags",
70+
"templateId": "COLLAPSE",
71+
"dataType": "string"
6672
}
6773
]
6874
}

0 commit comments

Comments
 (0)