mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-27 06:46:01 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4870f243fc | ||
|
|
fac30f59e6 | ||
|
|
775ed8a4aa |
@@ -31,6 +31,8 @@ Currency: `sh lean4/scripts/check_currency.sh origin/main`.
|
||||
| GH-24 | rescan | with `security.rescan_interval` set, artifacts whose scan never completed are scanned and old results refreshed | correctness (scans lost to a restart stayed unscanned; new CVEs never picked up) | medium | not modelled (worker wiring) / `TestWorkersStartTheRescanWorker` | 378b873 |
|
||||
| GH-25 | scanners | an error result from one scanner is left out of the merge, so the row reads error only when every scanner failed; grype, npm-audit, govulncheck and pip-audit give correct results with the scanner image tool versions | correctness (false error, false clean) | high (grype, npm-audit and pip-audit failed on every package; govulncheck and a bare-archive grype scan read vulnerable packages clean) | `Security.old_error_poisons_clean`, `error_and_clean_reads_clean`, `all_error_reads_error`, `merged_not_error_when_one_ran` / `TestScanPackage_ErrorResultPlusCleanReadsClean`, `TestScanPackage_AllErrorResultsReadError`, `TestScanPackage_InfrastructureErrorResultsCountAsInfrastructure`, `TestScanMapsRealOutput`, `TestParseKeepsBothViaShapes`, `TestScanReadsPrettyPrintedFindings`, `TestScanAuditsTheReleaseFromARequirement` | 3731ca0 |
|
||||
| GH-26 | rescan | the rescan worker skips the entries the serve path skips, so Go `.mod` and `.info` rows are no longer scanned | cost (1316 of about 2780 rescans on production were these rows, about 3.3 s each) | low | `Cache.old_rescan_scanned_go_metadata`, `rescan_skips_what_serve_skips` / `TestRescanSkipsMetadataEntries` | d6044cd |
|
||||
| GH-27 | scanners | govulncheck counts findings in the scanned module only; dependency findings (minimum versions from its go.mod) and stdlib findings (the scanner toolchain) no longer attach to it | correctness (false vulnerable, and a false block when a dependency finding is critical) | medium (golang.org/x/net v0.56.0 carried x/crypto and x/text advisories on production) | `TestScanIgnoresFindingsInDependencies`, `TestScanReadsPrettyPrintedFindings` | 775ed8a |
|
||||
| GH-28 | scanners | OSV takes the fixed version from the range of the queried package | display (x/net findings showed the stdlib fix 1.26.9 instead of 0.60.0) | low | `TestScan_FixedVersionComesFromTheQueriedPackage` | fac30f5 |
|
||||
|
||||
### Exploit paths and reach
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ func (s *Scanner) Scan(ctx context.Context, registry, packageName, version strin
|
||||
cmd.Stderr = &stderr
|
||||
output, _ := cmd.Output() // govulncheck -json exits 0 whether or not it finds anything
|
||||
|
||||
vulns, err := parseFindings(output)
|
||||
vulns, err := parseFindings(output, module)
|
||||
if err != nil {
|
||||
return s.errorResult(ctx, registry, packageName, version,
|
||||
fmt.Sprintf("govulncheck failed: %v: %s", err, strings.TrimSpace(stderr.String())), stderr.String()), nil
|
||||
@@ -175,8 +175,10 @@ func hasPathElement(importPath, element string) bool {
|
||||
}
|
||||
|
||||
// parseFindings reads govulncheck's stream of JSON messages. An output without the config
|
||||
// message did not come from a completed run.
|
||||
func parseFindings(output []byte) ([]GovulncheckVuln, error) {
|
||||
// message did not come from a completed run. Only findings in the scanned module count:
|
||||
// dependency findings come from the minimum versions in its go.mod, which a consuming build
|
||||
// replaces with its own, and stdlib findings describe the scanner's toolchain.
|
||||
func parseFindings(output []byte, module string) ([]GovulncheckVuln, error) {
|
||||
summaries := make(map[string]string)
|
||||
var vulns []GovulncheckVuln
|
||||
seen := make(map[string]bool)
|
||||
@@ -194,14 +196,15 @@ func parseFindings(output []byte) ([]GovulncheckVuln, error) {
|
||||
sawConfig = true
|
||||
case msg.OSV != nil:
|
||||
summaries[msg.OSV.ID] = msg.OSV.Summary
|
||||
case msg.Finding != nil && msg.Finding.OSV != "" && !seen[msg.Finding.OSV]:
|
||||
case msg.Finding != nil && msg.Finding.OSV != "" && !seen[msg.Finding.OSV] &&
|
||||
len(msg.Finding.Trace) > 0 && msg.Finding.Trace[0].Module == module:
|
||||
seen[msg.Finding.OSV] = true
|
||||
v := GovulncheckVuln{OSV: msg.Finding.OSV, FixedVersion: msg.Finding.FixedVersion}
|
||||
if len(msg.Finding.Trace) > 0 {
|
||||
v.Module = msg.Finding.Trace[0].Module
|
||||
v.ModuleVersion = msg.Finding.Trace[0].Version
|
||||
}
|
||||
vulns = append(vulns, v)
|
||||
vulns = append(vulns, GovulncheckVuln{
|
||||
OSV: msg.Finding.OSV,
|
||||
FixedVersion: msg.Finding.FixedVersion,
|
||||
Module: msg.Finding.Trace[0].Module,
|
||||
ModuleVersion: msg.Finding.Trace[0].Version,
|
||||
})
|
||||
}
|
||||
}
|
||||
if !sawConfig {
|
||||
|
||||
@@ -86,16 +86,28 @@ func ids(res *metadata.ScanResult) map[string]string {
|
||||
func TestScanReadsPrettyPrintedFindings(t *testing.T) {
|
||||
// govulncheck -json prints indented objects, not one object per line.
|
||||
fakeGo(t, abs(t, "golist-gin-v1.6.0.txt"), 0, "")
|
||||
fakeGovulncheck(t, abs(t, "gin-v1.6.0-source-scan.stream"), 0, "")
|
||||
fakeGovulncheck(t, abs(t, "gin-v1.6.0.stream"), 0, "")
|
||||
|
||||
res, err := New(config.GovulncheckConfig{}).Scan(context.Background(), "go", "github.com/gin-gonic/gin/@v/v1.6.0.zip", "v1.6.0", module(t))
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, metadata.ScanStatusVulnerable, res.Status)
|
||||
assert.Equal(t, map[string]string{
|
||||
"GO-2022-0493": "v0.0.0-20220412211240-33da011f77ad",
|
||||
"GO-2026-5024": "v0.44.0",
|
||||
}, ids(res), "one entry per advisory, with the fixed version")
|
||||
"GO-2021-0052": "v1.7.7",
|
||||
"GO-2023-1737": "v1.9.1",
|
||||
}, ids(res), "one entry per advisory against gin, with the fixed version; the x/sys findings belong to a dependency")
|
||||
}
|
||||
|
||||
func TestScanIgnoresFindingsInDependencies(t *testing.T) {
|
||||
// gin's go.mod requires an old x/sys; a build that uses gin resolves its own x/sys version.
|
||||
fakeGo(t, abs(t, "golist-gin-v1.6.0.txt"), 0, "")
|
||||
fakeGovulncheck(t, abs(t, "gin-v1.6.0-source-scan.stream"), 0, "")
|
||||
|
||||
res, err := New(config.GovulncheckConfig{}).Scan(context.Background(), "go", "github.com/gin-gonic/gin/@v/v1.6.0.zip", "v1.6.0", module(t))
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, metadata.ScanStatusClean, res.Status)
|
||||
assert.Empty(t, res.Vulnerabilities)
|
||||
}
|
||||
|
||||
func TestScanAuditsTheModuleItself(t *testing.T) {
|
||||
|
||||
+25
-8
@@ -264,6 +264,7 @@ func (s *Scanner) cleanGoModuleName(packageName, version, ecosystem string) (str
|
||||
func (s *Scanner) convertOSVResult(osvResp *OSVResponse, registry, packageName, version string) *metadata.ScanResult {
|
||||
vulnerabilities := make([]metadata.Vulnerability, 0, len(osvResp.Vulns))
|
||||
severityCounts := make(map[string]int)
|
||||
queryName, _ := s.cleanGoModuleName(packageName, version, s.registryToEcosystem(registry))
|
||||
|
||||
for _, vuln := range osvResp.Vulns {
|
||||
// Determine severity from various sources
|
||||
@@ -277,7 +278,7 @@ func (s *Scanner) convertOSVResult(osvResp *OSVResponse, registry, packageName,
|
||||
}
|
||||
|
||||
// Find fixed version
|
||||
fixedVersion := s.findFixedVersion(&vuln, version)
|
||||
fixedVersion := s.findFixedVersion(&vuln, queryName)
|
||||
|
||||
vulnerabilities = append(vulnerabilities, metadata.Vulnerability{
|
||||
ID: vuln.ID,
|
||||
@@ -352,14 +353,30 @@ func (s *Scanner) determineSeverity(vuln *OSVVulnerability) string {
|
||||
return metadata.NormalizeSeverity(rawSeverity)
|
||||
}
|
||||
|
||||
// findFixedVersion extracts the fixed version from OSV affected ranges
|
||||
func (s *Scanner) findFixedVersion(vuln *OSVVulnerability, currentVersion string) string {
|
||||
// findFixedVersion returns the first fixed version in the ranges for the queried package; an
|
||||
// advisory can cover several packages (stdlib and golang.org/x/net) with different fixes.
|
||||
func (s *Scanner) findFixedVersion(vuln *OSVVulnerability, name string) string {
|
||||
fallback := ""
|
||||
for _, affected := range vuln.Affected {
|
||||
for _, r := range affected.Ranges {
|
||||
for _, event := range r.Events {
|
||||
if event.Fixed != "" {
|
||||
return event.Fixed
|
||||
}
|
||||
fixed := firstFixed(affected.Ranges)
|
||||
if fixed == "" {
|
||||
continue
|
||||
}
|
||||
if strings.EqualFold(affected.Package.Name, name) {
|
||||
return fixed
|
||||
}
|
||||
if fallback == "" {
|
||||
fallback = fixed
|
||||
}
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func firstFixed(ranges []OSVRange) string {
|
||||
for _, r := range ranges {
|
||||
for _, event := range r.Events {
|
||||
if event.Fixed != "" {
|
||||
return event.Fixed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,3 +44,22 @@ func TestScan_FullQueryURLIsKept(t *testing.T) {
|
||||
t.Errorf("request path = %q, want /v1/query", gotPath)
|
||||
}
|
||||
}
|
||||
|
||||
// An advisory that covers the stdlib and x/net lists the stdlib range first; the fixed version
|
||||
// shown for x/net must come from the x/net range.
|
||||
func TestScan_FixedVersionComesFromTheQueriedPackage(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
_, _ = w.Write([]byte(`{"vulns":[{"id":"GO-2026-6612","summary":"s","affected":[
|
||||
{"package":{"name":"stdlib","ecosystem":"Go"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"1.26.9"}]}]},
|
||||
{"package":{"name":"golang.org/x/net","ecosystem":"Go"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"0.60.0"}]}]}]}]}`))
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
|
||||
res, err := New(config.OSVConfig{APIURL: srv.URL}).Scan(context.Background(), "go", "golang.org/x/net/@v/v0.56.0.zip", "v0.56.0", "")
|
||||
if err != nil {
|
||||
t.Fatalf("Scan: %v", err)
|
||||
}
|
||||
if len(res.Vulnerabilities) != 1 || res.Vulnerabilities[0].FixedIn != "0.60.0" {
|
||||
t.Fatalf("vulnerabilities = %+v, want one fixed in 0.60.0", res.Vulnerabilities)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user