feat(scanner): match bypasses and merge findings across advisory aliases

Scanners report one advisory under different ids, such as a GHSA id from
OSV and the CVE id from Trivy. Findings now carry an aliases list.
The merge folds findings that share any id into one finding. A bypass
for any id of a finding now covers it. Stored findings without aliases
still load and match by their own id.
This commit is contained in:
2026-11-24 01:39:51 +00:00
parent 64793f9c7e
commit 43e075baf3
20 changed files with 617 additions and 66 deletions
+18 -2
View File
@@ -161,6 +161,7 @@ func (s *Scanner) convertGrypeResult(grypeResult *GrypeResult, registry, package
Description: match.Vulnerability.Description,
References: match.Vulnerability.URLs,
FixedIn: fixedIn,
Aliases: metadata.NormalizeAliases(match.Vulnerability.ID, grypeAliases(match)...),
})
}
@@ -205,8 +206,14 @@ type GrypeSource struct {
}
type GrypeMatch struct {
Artifact GrypeArtifact `json:"artifact"`
Vulnerability GrypeVulnerability `json:"vulnerability"`
Artifact GrypeArtifact `json:"artifact"`
Vulnerability GrypeVulnerability `json:"vulnerability"`
RelatedVulnerabilities []GrypeRelatedVuln `json:"relatedVulnerabilities"`
}
// GrypeRelatedVuln is another id of the matched advisory, such as the CVE of a GHSA match.
type GrypeRelatedVuln struct {
ID string `json:"id"`
}
type GrypeVulnerability struct {
@@ -230,3 +237,12 @@ type GrypeArtifact struct {
// Version returns the version the last successful health check reported.
func (s *Scanner) Version() string { return s.version.Version() }
// grypeAliases lists the ids grype relates to a match, plus any named by its advisory links.
func grypeAliases(match GrypeMatch) []string {
out := make([]string, 0, len(match.RelatedVulnerabilities))
for _, rel := range match.RelatedVulnerabilities {
out = append(out, rel.ID)
}
return append(out, metadata.ExtractAdvisoryIDs(match.Vulnerability.URLs...)...)
}
+16
View File
@@ -124,3 +124,19 @@ func TestPurl(t *testing.T) {
assert.Equal(t, tc.want, purl(tc.registry, tc.name, tc.version), "%s %s", tc.registry, tc.name)
}
}
func TestFindingsCarryTheRelatedCVEAsAnAlias(t *testing.T) {
data, err := os.ReadFile(fixture("purl-minimist-0.0.8.json"))
require.NoError(t, err)
parsed, err := parse(data)
require.NoError(t, err)
res := New(config.GrypeConfig{}).convertGrypeResult(parsed, "npm", "minimist", "0.0.8")
aliases := map[string][]string{}
for _, v := range res.Vulnerabilities {
aliases[v.ID] = v.Aliases
}
assert.Equal(t, []string{"CVE-2021-44906"}, aliases["GHSA-xvch-5gv4-984h"])
assert.Equal(t, []string{"CVE-2020-7598"}, aliases["GHSA-vh95-rmgr-6w4m"])
}