diff --git a/pkg/vex/vex.go b/pkg/vex/vex.go index 6aa645e..a90a739 100644 --- a/pkg/vex/vex.go +++ b/pkg/vex/vex.go @@ -145,13 +145,8 @@ func (vexDoc *VEX) EffectiveStatement(product, vulnID string) (s *Statement) { SortStatements(statements, t) for i := len(statements) - 1; i >= 0; i-- { - if statements[i].Vulnerability.ID != vulnID { - continue - } - for _, p := range statements[i].Products { - if p.ID == product { - return &statements[i] - } + if statements[i].Matches(vulnID, product, nil) { + return &statements[i] } } return nil diff --git a/pkg/vex/vex_test.go b/pkg/vex/vex_test.go index f6f97b3..960e3d7 100644 --- a/pkg/vex/vex_test.go +++ b/pkg/vex/vex_test.go @@ -28,7 +28,7 @@ func TestEffectiveStatement(t *testing.T) { vexDoc: &VEX{ Statements: []Statement{ { - Vulnerability: Vulnerability{ID: "CVE-2014-123456"}, + Vulnerability: Vulnerability{Name: "CVE-2014-123456"}, Timestamp: &date1, Products: []Product{{Component: Component{ID: "pkg:deb/pkg@1.0"}}}, Status: StatusNotAffected, @@ -45,13 +45,13 @@ func TestEffectiveStatement(t *testing.T) { vexDoc: &VEX{ Statements: []Statement{ { - Vulnerability: Vulnerability{ID: "CVE-2014-123456"}, + Vulnerability: Vulnerability{Name: "CVE-2014-123456"}, Timestamp: &date1, Products: []Product{{Component: Component{ID: "pkg:deb/pkg@1.0"}}}, Status: StatusUnderInvestigation, }, { - Vulnerability: Vulnerability{ID: "CVE-2014-123456"}, + Vulnerability: Vulnerability{Name: "CVE-2014-123456"}, Timestamp: &date2, Products: []Product{{Component: Component{ID: "pkg:deb/pkg@1.0"}}}, Status: StatusNotAffected, @@ -68,13 +68,13 @@ func TestEffectiveStatement(t *testing.T) { vexDoc: &VEX{ Statements: []Statement{ { - Vulnerability: Vulnerability{ID: "CVE-2014-123456"}, + Vulnerability: Vulnerability{Name: "CVE-2014-123456"}, Timestamp: &date1, Products: []Product{{Component: Component{ID: "pkg:deb/pkg@1.0"}}}, Status: StatusUnderInvestigation, }, { - Vulnerability: Vulnerability{ID: "CVE-2014-123456"}, + Vulnerability: Vulnerability{Name: "CVE-2014-123456"}, Timestamp: &date2, Products: []Product{{Component: Component{ID: "pkg:deb/pkg@2.0"}}}, Status: StatusNotAffected, @@ -87,6 +87,32 @@ func TestEffectiveStatement(t *testing.T) { expectedDate: &date1, expectedStatus: StatusUnderInvestigation, }, + "Vulnerability aliases": { + vexDoc: &VEX{ + Statements: []Statement{ + { + Vulnerability: Vulnerability{ + Name: "CVE-2014-123456", + Aliases: []VulnerabilityID{"ghsa-92xj-mqp7-vmcj"}, + }, + Timestamp: &date1, + Products: []Product{{Component: Component{ID: "pkg:deb/pkg@1.0"}}}, + Status: StatusUnderInvestigation, + }, + { + Vulnerability: Vulnerability{ID: "CVE-2014-123456"}, + Timestamp: &date2, + Products: []Product{{Component: Component{ID: "pkg:deb/pkg@2.0"}}}, + Status: StatusNotAffected, + }, + }, + }, + vulnID: "ghsa-92xj-mqp7-vmcj", + product: "pkg:deb/pkg@1.0", + shouldNil: false, + expectedDate: &date1, + expectedStatus: StatusUnderInvestigation, + }, } { s := tc.vexDoc.EffectiveStatement(tc.product, tc.vulnID) if tc.shouldNil {