Skip to content

Commit

Permalink
grabbing the value of applicability from the sarif and checking by it.
Browse files Browse the repository at this point in the history
also added the right types
  • Loading branch information
eyalk007 committed Sep 3, 2024
1 parent ca8535e commit 4fa2643
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.net.http.HttpResponse
import java.nio.file.Paths

plugins {
id "org.jetbrains.intellij" version "1.16.0"
id "org.jetbrains.intellij" version "1.17.0"
id "java"
id "maven-publish"
id "de.undercouch.download" version "5.3.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public JFrogSecurityWarning(
this.codeFlows = codeFlows;
}

public JFrogSecurityWarning(SarifResult result, SourceCodeScanType reporter) {
public JFrogSecurityWarning(SarifResult result, SourceCodeScanType reporter, Rule rule) {
this(getFirstRegion(result).getStartLine() - 1,
getFirstRegion(result).getStartColumn() - 1,
getFirstRegion(result).getEndLine() - 1,
Expand All @@ -62,7 +62,7 @@ public JFrogSecurityWarning(SarifResult result, SourceCodeScanType reporter) {
result.getRuleId(),
getFirstRegion(result).getSnippet().getText(),
reporter,
!result.getKind().equals("pass"),
(!result.getKind().equals("pass") && (rule.getRuleProperties().map(properties -> !properties.getApplicability().equals("not_applicable")).orElse(true))),
Severity.fromSarif(result.getSeverity()),
convertCodeFlowsToFindingInfo(result.getCodeFlows())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ protected boolean isPackageTypeSupported(PackageManagerType type) {
protected List<JFrogSecurityWarning> parseOutputSarif(Path outputFile) throws IOException {
Output output = getOutputObj(outputFile);
List<JFrogSecurityWarning> warnings = new ArrayList<>();
output.getRuns().forEach(run -> run.getResults().stream().filter(SarifResult::isNotSuppressed).forEach(result -> warnings.add(new JFrogSecurityWarning(result, scanType))));

output.getRuns().forEach(run -> run.getResults().stream().filter(SarifResult::isNotSuppressed).forEach(result -> warnings.add(new JFrogSecurityWarning(result, scanType, run.getRuleFromRunById(result.getRuleId())))));

Optional<Run> run = output.getRuns().stream().findFirst();
if (run.isPresent()) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/jfrog/ide/idea/scan/data/Rule.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;
import java.util.Optional;

public class Rule {

Expand All @@ -15,6 +16,9 @@ public class Rule {
@JsonProperty("fullDescription")
private Message fullDescription;

@JsonProperty("properties")
private RuleProperties properties;

public String getId() {
return id;
}
Expand Down Expand Up @@ -43,6 +47,10 @@ public void setFullDescription(Message fullDescription) {
this.fullDescription = fullDescription;
}

public Optional<RuleProperties> getRuleProperties() {
return Optional.ofNullable(properties);
}

@Override
public int hashCode() {
return Objects.hash(id);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/jfrog/ide/idea/scan/data/RuleProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.jfrog.ide.idea.scan.data;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;

@Getter
public class RuleProperties {

@JsonProperty("conclusion")
private String conclusion;

@JsonProperty("applicability")
private String applicability;

}
9 changes: 9 additions & 0 deletions src/main/java/com/jfrog/ide/idea/scan/data/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ public List<SarifResult> getResults() {
return results;
}

public Rule getRuleFromRunById(String ruleId) {
List<Rule> rules = this.getTool().getDriver().getRules();
return rules.stream()
.filter(rule -> rule.getId().equals(ruleId))
.findFirst()
.orElseThrow(() -> new NoSuchElementException("No rule found with id: " + ruleId));

}

public void setResults(List<SarifResult> results) {
this.results = results;
}
Expand Down

0 comments on commit 4fa2643

Please sign in to comment.