Skip to content

Commit d5c1d79

Browse files
fix: skip vulnerabilities with empty affected ranges in combine-to-osv (#5039)
Added a helper `hasRanges` to ensure that vulnerabilities missing ranges in their `affected` blocks are skipped and not uploaded unless they are explicitly included in the `mandatoryCVEIDs` slice. Also updated `main_test.go` to assert this new logic correctly. deals with https://osv.dev/vulnerability/CVE-2024-2002 having no ranges --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 5b03702 commit d5c1d79

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

vulnfeeds/cmd/combine-to-osv/main.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func combineIntoOSV(cve5osv map[models.CVEID]*osvschema.Vulnerability, nvdosv ma
191191
baseOSV = cve5
192192
}
193193

194-
if len(baseOSV.GetAffected()) == 0 {
194+
if len(baseOSV.GetAffected()) == 0 || !hasRanges(baseOSV.GetAffected()) {
195195
// check if part exists.
196196
if !slices.Contains(mandatoryCVEIDs, string(cveID)) {
197197
continue
@@ -202,7 +202,7 @@ func combineIntoOSV(cve5osv map[models.CVEID]*osvschema.Vulnerability, nvdosv ma
202202

203203
// Add any remaining CVEs from NVD that were not in the advisory data.
204204
for cveID, nvd := range nvdosv {
205-
if len(nvd.GetAffected()) == 0 {
205+
if len(nvd.GetAffected()) == 0 || !hasRanges(nvd.GetAffected()) {
206206
continue
207207
}
208208
osvRecords[cveID] = nvd
@@ -364,6 +364,16 @@ func pickAffectedInformation(cve5Affected []*osvschema.Affected, nvdAffected []*
364364
return combinedAffected
365365
}
366366

367+
func hasRanges(affected []*osvschema.Affected) bool {
368+
for _, a := range affected {
369+
if len(a.GetRanges()) > 0 {
370+
return true
371+
}
372+
}
373+
374+
return false
375+
}
376+
367377
// getRangeBoundaryVersions extracts the introduced and fixed versions from a slice of OSV events.
368378
// It iterates through the events and returns the last non-empty "introduced" and "fixed" versions found.
369379
func getRangeBoundaryVersions(events []*osvschema.Event) (introduced, fixed string) {

vulnfeeds/cmd/combine-to-osv/main_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func TestCombineIntoOSV(t *testing.T) {
4949
// CVE-2023-0002: from nvd only
5050
// CVE-2023-0003: from cve5, no affected, but in noPkgCVEs
5151
// CVE-2023-0004: from cve5, no affected, not in noPkgCVEs, so skipped
52-
if len(combined) != 4 {
53-
t.Errorf("Expected 4 combined vulnerabilities, got %d", len(combined))
52+
if len(combined) != 2 {
53+
t.Errorf("Expected 2 combined vulnerabilities, got %d", len(combined))
5454
}
5555

5656
// Test case 1: Merged CVE
@@ -109,22 +109,22 @@ func TestCombineIntoOSV(t *testing.T) {
109109
t.Errorf("CVE-2023-1234: affected range mismatch (-want +got):\n%s", diff)
110110
}
111111

112-
// Test case 2: CVE only in cve5
113-
if _, ok = combined["CVE-2023-0001"]; !ok {
114-
t.Error("Expected combined map to contain CVE-2023-0001")
112+
// Test case 2: CVE only in cve5 (has no ranges, so it should be skipped)
113+
if _, ok = combined["CVE-2023-0001"]; ok {
114+
t.Error("Expected combined map to NOT contain CVE-2023-0001 because it has no ranges")
115115
}
116116

117-
// Test case 3: CVE only in nvd
118-
if _, ok = combined["CVE-2023-0002"]; !ok {
119-
t.Error("Expected combined map to contain CVE-2023-0002")
117+
// Test case 3: CVE only in nvd (has no ranges, so it should be skipped)
118+
if _, ok = combined["CVE-2023-0002"]; ok {
119+
t.Error("Expected combined map to NOT contain CVE-2023-0002 because it has no ranges")
120120
}
121121

122-
// Test case 4: No affected, in noPkgCVEs
122+
// Test case 4: No ranges, in noPkgCVEs (should be kept)
123123
if _, ok = combined["CVE-2023-0003"]; !ok {
124124
t.Error("Expected combined map to contain CVE-2023-0003")
125125
}
126126

127-
// Test case 5: No affected, not in noPkgCVEs
127+
// Test case 5: No ranges, not in noPkgCVEs (should be skipped)
128128
if _, ok = combined["CVE-2023-0004"]; ok {
129129
t.Error("Expected combined map to NOT contain CVE-2023-0004")
130130
}

0 commit comments

Comments
 (0)