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

Backport: Fix Trivy analyzer vulnerability matching for Go packages #4395

Merged
merged 1 commit into from
Nov 20, 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 @@ -204,7 +204,11 @@ public void analyze(final List<Component> components) {
var name = component.getPurl().getName();

if (component.getPurl().getNamespace() != null) {
name = component.getPurl().getNamespace() + ":" + name;
if (PackageURL.StandardTypes.GOLANG.equals(component.getPurl().getType())) {
name = component.getPurl().getNamespace() + "/" + name;
} else {
name = component.getPurl().getNamespace() + ":" + name;
}
}

if (!PurlType.UNKNOWN.getAppType().equals(appType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void testWithPackageWithoutTrivyProperties() {
assertThat(qm.getAllVulnerabilities(component)).isEmpty();
}

/**
/**
* This test documents the case where Trivy is able to correlate a package with vulnerabilities
* when additional properties provided. When including libc6 in an SBOM,
* Trivy adds metadata to the component, which among other things includes alternative package names.
Expand Down Expand Up @@ -346,7 +346,7 @@ public void testWithPackageWithTrivyProperties() {
});
}

/**
/**
* This test documents the case where Trivy generates a sbom and operative system is not entirely on distro qualifier.
* <p>
* Here's an excerpt of the properties included:
Expand Down Expand Up @@ -436,4 +436,25 @@ public void testWithPackageWithTrivyPropertiesWithDistroWithoutOS() {
assertThat(vuln.getReferences()).isNotBlank();
});
}

@Test // https://github.com/DependencyTrack/dependency-track/issues/4376
public void testWithGoPackage() {
final var project = new Project();
project.setName("acme-app");
qm.persist(project);

final var component = new Component();
component.setProject(project);
component.setName("golang/github.com/nats-io/nkeys");
component.setVersion("0.4.4");
component.setClassifier(Classifier.LIBRARY);
component.setPurl("pkg:golang/github.com/nats-io/nkeys@0.4.4");
qm.persist(component);

final var analysisEvent = new TrivyAnalysisEvent(List.of(component));
new TrivyAnalysisTask().inform(analysisEvent);

assertThat(qm.getAllVulnerabilities(component)).hasSizeGreaterThanOrEqualTo(1);
}

}