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
+61
View File
@@ -0,0 +1,61 @@
package app
import (
"context"
"testing"
"time"
"github.com/lukaszraczylo/gohoarder/pkg/metadata"
)
func seedAliased(t *testing.T, a *App) {
t.Helper()
ctx := context.Background()
now := time.Now()
if err := a.metadata.SavePackage(ctx, &metadata.Package{
Registry: "npm", Name: "aliased", Version: "1.0.0", StorageKey: "npm/aliased", Size: 10, CachedAt: now, LastAccessed: now,
}); err != nil {
t.Fatalf("SavePackage: %v", err)
}
if err := a.metadata.SaveScanResult(ctx, &metadata.ScanResult{
Registry: "npm", PackageName: "aliased", PackageVersion: "1.0.0", Scanner: "osv", Status: metadata.ScanStatusVulnerable, ScannedAt: now,
VulnerabilityCount: 1,
Vulnerabilities: []metadata.Vulnerability{{
ID: "GHSA-xvch-5gv4-984h", Aliases: []string{"CVE-2021-44906"}, Severity: "critical", DetectedBy: []string{"osv"},
}},
}); err != nil {
t.Fatalf("SaveScanResult: %v", err)
}
}
func TestDetailsShowAliasesAndHonourABypassOnAnAlias(t *testing.T) {
a, _ := newScanningApp(t)
a.config.Security.BlockOnSeverity = "critical"
seedAliased(t, a)
held, _ := getJSON(t, a, "/api/packages/npm/aliased/1.0.0/vulnerabilities")
if jsonAt(held, "decision", "verdict") != VerdictHeld {
t.Fatalf("verdict before the bypass = %v, want held", jsonAt(held, "decision", "verdict"))
}
if got, _ := jsonAt(held, "vulnerabilities", 0, "aliases").([]any); len(got) != 1 || got[0] != "CVE-2021-44906" {
t.Errorf("aliases = %v, want [CVE-2021-44906]", got)
}
if err := a.metadata.SaveCVEBypass(context.Background(), &metadata.CVEBypass{
Type: metadata.BypassTypeCVE, Target: "cve-2021-44906", Reason: "not reachable", CreatedBy: "alice",
Active: true, ExpiresAt: time.Now().Add(time.Hour),
}); err != nil {
t.Fatal(err)
}
waved, _ := getJSON(t, a, "/api/packages/npm/aliased/1.0.0/vulnerabilities")
if jsonAt(waved, "decision", "verdict") != VerdictBypassed {
t.Errorf("verdict with a CVE bypass = %v, want bypassed", jsonAt(waved, "decision", "verdict"))
}
if jsonAt(waved, "vulnerabilities", 0, "bypassed") != true {
t.Errorf("finding bypassed = %v, want true", jsonAt(waved, "vulnerabilities", 0, "bypassed"))
}
if jsonAt(waved, "vulnerabilities", 0, "bypass", "created_by") != "alice" {
t.Errorf("bypass = %v", jsonAt(waved, "vulnerabilities", 0, "bypass"))
}
}
+2 -1
View File
@@ -117,7 +117,7 @@ func (a *App) handleVulnerabilities(c fiber.Ctx) error {
var bypassInfo map[string]interface{}
// Check if this CVE is bypassed
if bypass, ok := bypassedCVEs[strings.ToUpper(vuln.ID)]; ok {
if bypass, ok := metadata.BypassFor(bypassedCVEs, vuln); ok {
bypassed = true
bypassInfo = map[string]interface{}{
"id": bypass.ID,
@@ -138,6 +138,7 @@ func (a *App) handleVulnerabilities(c fiber.Ctx) error {
"references": vuln.References,
"fixed_in": vuln.FixedIn,
"detected_by": vuln.DetectedBy,
"aliases": vuln.Aliases,
"bypassed": bypassed,
}