Skip to content

Commit

Permalink
feat: show from which dependency the CVE comes in failure report (#7224)
Browse files Browse the repository at this point in the history
  • Loading branch information
yarisvt authored Dec 7, 2024
1 parent 97c3cee commit 5245930
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
11 changes: 9 additions & 2 deletions ant/src/main/java/org/owasp/dependencycheck/taskdefs/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.concurrent.NotThreadSafe;

import org.apache.tools.ant.BuildException;
Expand All @@ -35,6 +37,7 @@
import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
import org.owasp.dependencycheck.dependency.Dependency;
import org.owasp.dependencycheck.dependency.Vulnerability;
import org.owasp.dependencycheck.dependency.naming.Identifier;
import org.owasp.dependencycheck.exception.ExceptionCollection;
import org.owasp.dependencycheck.exception.ReportException;
import org.owasp.dependencycheck.reporting.ReportGenerator.Format;
Expand Down Expand Up @@ -2301,8 +2304,12 @@ private void checkForFailure(Dependency[] dependencies) throws BuildException {
|| (failBuildOnCVSS <= 0.0f)) {
if (addName) {
addName = false;
ids.append(NEW_LINE).append(d.getFileName()).append(": ");
ids.append(v.getName());
ids.append(NEW_LINE).append(d.getFileName()).append(" (")
.append(Stream.concat(d.getSoftwareIdentifiers().stream(), d.getVulnerableSoftwareIdentifiers().stream())
.map(Identifier::getValue)
.collect(Collectors.joining(", ")))
.append("): ")
.append(v.getName());
} else {
ids.append(", ").append(v.getName());
}
Expand Down
9 changes: 8 additions & 1 deletion cli/src/main/java/org/owasp/dependencycheck/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
import java.util.List;
import java.util.Set;

import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.cli.ParseException;
import org.apache.tools.ant.DirectoryScanner;
import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
import org.owasp.dependencycheck.dependency.Dependency;
import org.owasp.dependencycheck.dependency.Vulnerability;
import org.apache.tools.ant.types.LogLevel;
import org.owasp.dependencycheck.data.update.exception.UpdateException;
import org.owasp.dependencycheck.dependency.naming.Identifier;
import org.owasp.dependencycheck.exception.ExceptionCollection;
import org.owasp.dependencycheck.exception.ReportException;
import org.owasp.dependencycheck.utils.Downloader;
Expand Down Expand Up @@ -331,7 +334,11 @@ private int determineReturnCode(Engine engine, float cvssFailScore) {
}
if (addName) {
addName = false;
ids.append(NEW_LINE).append(d.getFileName()).append(": ");
ids.append(NEW_LINE).append(d.getFileName()).append(" (")
.append(Stream.concat(d.getSoftwareIdentifiers().stream(), d.getVulnerableSoftwareIdentifiers().stream())
.map(Identifier::getValue)
.collect(Collectors.joining(", ")))
.append("): ");
ids.append(v.getName()).append('(').append(score).append(')');
} else {
ids.append(", ").append(v.getName()).append('(').append(score).append(')');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,12 @@ private void checkForFailure(Dependency[] dependencies) throws ScanAgentExceptio
|| (failBuildOnCVSS <= 0.0f)) {
if (addName) {
addName = false;
ids.append(NEW_LINE).append(d.getFileName()).append(": ");
ids.append(v.getName());
ids.append(NEW_LINE).append(d.getFileName()).append(" (")
.append(Stream.concat(d.getSoftwareIdentifiers().stream(), d.getVulnerableSoftwareIdentifiers().stream())
.map(Identifier::getValue)
.collect(Collectors.joining(", ")))
.append("): ")
.append(v.getName());
} else {
ids.append(", ").append(v.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.github.packageurl.PackageURL.StandardTypes;
import com.github.packageurl.PackageURL;
import io.github.jeremylong.jcs3.slf4j.Slf4jAdapter;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
Expand Down Expand Up @@ -2662,8 +2664,12 @@ protected void checkForFailure(Dependency[] dependencies) throws MojoFailureExce
}
if (addName) {
addName = false;
ids.append(NEW_LINE).append(d.getFileName()).append(": ");
ids.append(name);
ids.append(NEW_LINE).append(d.getFileName()).append(" (")
.append(Stream.concat(d.getSoftwareIdentifiers().stream(), d.getVulnerableSoftwareIdentifiers().stream())
.map(Identifier::getValue)
.collect(Collectors.joining(", ")))
.append("): ")
.append(name);
} else {
ids.append(", ").append(name);
}
Expand Down

0 comments on commit 5245930

Please sign in to comment.