Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Support multiple rule names for AppScan #428

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,27 @@ protected void configure() {
.findFirst();

annotation.ifPresent(
providedAppScanScan ->
providedAppScanScan -> {
if (!providedAppScanScan.ruleName().isEmpty()) {
bind(RuleSarif.class)
.annotatedWith(providedAppScanScan)
.toInstance(map.getOrDefault(providedAppScanScan.ruleName(), RuleSarif.EMPTY)));
.toInstance(map.getOrDefault(providedAppScanScan.ruleName(), RuleSarif.EMPTY));
} else if (providedAppScanScan.ruleNames().length > 0) {

RuleSarif ruleSarif = RuleSarif.EMPTY;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand this logic. We loop through the names and match/break on the first one?

I was expecting this would look much more like "merge N results together" kind of change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, we see the different names as a result of different kinds of scans (e.g. from source or from a binary), so I wouldn't expect to see a SARIF with results from multiple of the names specified on the annotation in the same SARIF file.

In general, I thought we were trying to avoid merging SARIF at this stage?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, true. It will only be one or the other, you're right.

for (final String ruleName : providedAppScanScan.ruleNames()) {
final var result = map.get(ruleName);
if (result != null) {
ruleSarif = result;
break;
}
}

bind(RuleSarif.class).annotatedWith(providedAppScanScan).toInstance(ruleSarif);
} else {
throw new IllegalStateException("No rule name provided in " + providedAppScanScan);
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ public SarifSchema210 rawDocument() {
}

/**
* This returns the "ruleId" element, which has a value like "SA2813462719". The "message[text]"
* field has a more human-readable value like "SQL Injection". To stay aligned with other tools
* that use a more strict ID, we use the rule ID.
* This returns the "message[text]" field from the SARIF results. This is a human-readable value
* like "SQL Injection". We would ordinarily use this as the rule ID but this value is different
* each time we retrieve the SARIF for a given scan
*/
@Override
public String getRule() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
public @interface ProvidedAppScanScan {

/** The AppScan rule name, which shows up as the "message text" in the SARIF results. */
String ruleName();
String ruleName() default "";

/** The AppScan rule names, which show up as the "message text" in the SARIF results. */
String[] ruleNames() default {};
}
Loading