mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-26 06:37:07 +00:00
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:
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -53,6 +54,7 @@ type OSVVulnerability struct {
|
||||
DatabaseSpecific map[string]interface{} `json:"database_specific,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Summary string `json:"summary"`
|
||||
Aliases []string `json:"aliases,omitempty"`
|
||||
Details string `json:"details"`
|
||||
Severity []OSVSeverity `json:"severity,omitempty"`
|
||||
References []OSVReference `json:"references,omitempty"`
|
||||
@@ -287,6 +289,7 @@ func (s *Scanner) convertOSVResult(osvResp *OSVResponse, registry, packageName,
|
||||
Description: vuln.Details,
|
||||
References: references,
|
||||
FixedIn: fixedVersion,
|
||||
Aliases: metadata.NormalizeAliases(vuln.ID, append(slices.Clone(vuln.Aliases), metadata.ExtractAdvisoryIDs(references...)...)...),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -63,3 +63,21 @@ func TestScan_FixedVersionComesFromTheQueriedPackage(t *testing.T) {
|
||||
t.Fatalf("vulnerabilities = %+v, want one fixed in 0.60.0", res.Vulnerabilities)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertOSVResultKeepsAliases(t *testing.T) {
|
||||
s := New(config.OSVConfig{})
|
||||
resp := &OSVResponse{Vulns: []OSVVulnerability{{
|
||||
ID: "GHSA-xvch-5gv4-984h",
|
||||
Aliases: []string{"CVE-2021-44906", "ghsa-xvch-5gv4-984h"},
|
||||
References: []OSVReference{
|
||||
{Type: "ADVISORY", URL: "https://nvd.nist.gov/vuln/detail/CVE-2021-44906"},
|
||||
{Type: "ADVISORY", URL: "https://github.com/advisories/GHSA-xvch-5gv4-984h"},
|
||||
},
|
||||
}}}
|
||||
|
||||
res := s.convertOSVResult(resp, "npm", "minimist", "0.0.8")
|
||||
|
||||
if got := res.Vulnerabilities[0].Aliases; len(got) != 1 || got[0] != "CVE-2021-44906" {
|
||||
t.Errorf("aliases = %v, want only CVE-2021-44906", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user