Skip to content

Commit bf886d3

Browse files
authored
✨ Support multiple rule names for AppScan (#428)
- **:sparkles: support muitiple rule names in AppScan** - **:bulb: Improve docs for AppScan getRule accessor**
1 parent 6670a3d commit bf886d3

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

plugins/codemodder-plugin-appscan/src/main/java/io/codemodder/providers/sarif/appscan/AppScanModule.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,27 @@ protected void configure() {
4141
.findFirst();
4242

4343
annotation.ifPresent(
44-
providedAppScanScan ->
44+
providedAppScanScan -> {
45+
if (!providedAppScanScan.ruleName().isEmpty()) {
4546
bind(RuleSarif.class)
4647
.annotatedWith(providedAppScanScan)
47-
.toInstance(map.getOrDefault(providedAppScanScan.ruleName(), RuleSarif.EMPTY)));
48+
.toInstance(map.getOrDefault(providedAppScanScan.ruleName(), RuleSarif.EMPTY));
49+
} else if (providedAppScanScan.ruleNames().length > 0) {
50+
51+
RuleSarif ruleSarif = RuleSarif.EMPTY;
52+
for (final String ruleName : providedAppScanScan.ruleNames()) {
53+
final var result = map.get(ruleName);
54+
if (result != null) {
55+
ruleSarif = result;
56+
break;
57+
}
58+
}
59+
60+
bind(RuleSarif.class).annotatedWith(providedAppScanScan).toInstance(ruleSarif);
61+
} else {
62+
throw new IllegalStateException("No rule name provided in " + providedAppScanScan);
63+
}
64+
});
4865
}
4966
}
5067
}

plugins/codemodder-plugin-appscan/src/main/java/io/codemodder/providers/sarif/appscan/AppScanRuleSarif.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ public SarifSchema210 rawDocument() {
107107
}
108108

109109
/**
110-
* This returns the "ruleId" element, which has a value like "SA2813462719". The "message[text]"
111-
* field has a more human-readable value like "SQL Injection". To stay aligned with other tools
112-
* that use a more strict ID, we use the rule ID.
110+
* This returns the "message[text]" field from the SARIF results. This is a human-readable value
111+
* like "SQL Injection". We would ordinarily use this as the rule ID but this value is different
112+
* each time we retrieve the SARIF for a given scan
113113
*/
114114
@Override
115115
public String getRule() {

plugins/codemodder-plugin-appscan/src/main/java/io/codemodder/providers/sarif/appscan/ProvidedAppScanScan.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
public @interface ProvidedAppScanScan {
1515

1616
/** The AppScan rule name, which shows up as the "message text" in the SARIF results. */
17-
String ruleName();
17+
String ruleName() default "";
18+
19+
/** The AppScan rule names, which show up as the "message text" in the SARIF results. */
20+
String[] ruleNames() default {};
1821
}

0 commit comments

Comments
 (0)