Skip to content

Commit 2c251e0

Browse files
refactor(vulnfeeds): Uncouple Debian conversion from combine-to-osv converter (#3894)
Starting to deal with #2465 Closes #3899 --------- Co-authored-by: Rex P <[email protected]>
1 parent 749e06b commit 2c251e0

File tree

14 files changed

+847
-177
lines changed

14 files changed

+847
-177
lines changed

deployment/clouddeploy/gke-workers/environments/oss-vdb-test/debian-cve-convert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ spec:
1313
- name: GOOGLE_CLOUD_PROJECT
1414
value: oss-vdb-test
1515
- name: OUTPUT_GCS_BUCKET
16-
value: osv-test-cve-osv-conversion
16+
value: osv-test-debian-osv

deployment/clouddeploy/gke-workers/environments/oss-vdb/debian-cve-convert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ spec:
1313
- name: GOOGLE_CLOUD_PROJECT
1414
value: oss-vdb
1515
- name: OUTPUT_GCS_BUCKET
16-
value: cve-osv-conversion
16+
value: debian-osv

vulnfeeds/cmd/combine-to-osv/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Combine [`PackageInfo`](https://github.com/google/osv.dev/blob/2c22e9534a521c6c6
99
To address the generation of CVE records from multiple disparate sources (all requiring a common record prefix):
1010

1111
* Alpine, by [this code](../alpine)
12-
* Debian, by [this code](../debian)
1312
* the NVD, by [this code](../nvd-cve-osv)
1413

1514
## How

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

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ const (
2525

2626
alpineEcosystem = "Alpine"
2727
alpineSecurityTrackerURL = "https://security.alpinelinux.org/vuln"
28-
debianEcosystem = "Debian"
29-
debianSecurityTrackerURL = "https://security-tracker.debian.org/tracker"
3028
)
3129

3230
func main() {
@@ -47,7 +45,7 @@ func main() {
4745
logger.Fatal("Can't create output path", slog.Any("err", err))
4846
}
4947

50-
allCves := loadAllCVEs(*cvePath)
48+
allCves := vulns.LoadAllCVEs(*cvePath)
5149
allParts, cveModifiedMap := loadParts(*partsInputPath)
5250
combinedData := combineIntoOSV(allCves, allParts, *cveListPath, cveModifiedMap)
5351
writeOSVFile(combinedData, *osvOutputPath)
@@ -166,14 +164,10 @@ func combineIntoOSV(loadedCves map[cves.CVEID]cves.Vulnerability, allParts map[c
166164
}
167165
}
168166

169-
addedDebianURL := false
170167
addedAlpineURL := false
171168
for _, pkgInfo := range allParts[cveID] {
172169
convertedCve.AddPkgInfo(pkgInfo)
173-
if strings.HasPrefix(pkgInfo.Ecosystem, debianEcosystem) && !addedDebianURL {
174-
addReference(string(cveID), debianEcosystem, convertedCve)
175-
addedDebianURL = true
176-
} else if strings.HasPrefix(pkgInfo.Ecosystem, alpineEcosystem) && !addedAlpineURL {
170+
if strings.HasPrefix(pkgInfo.Ecosystem, alpineEcosystem) && !addedAlpineURL {
177171
addReference(string(cveID), alpineEcosystem, convertedCve)
178172
addedAlpineURL = true
179173
}
@@ -209,47 +203,11 @@ func writeOSVFile(osvData map[cves.CVEID]*vulns.Vulnerability, osvOutputPath str
209203
logger.Info("Successfully written OSV files", slog.Int("count", len(osvData)))
210204
}
211205

212-
// loadAllCVEs loads the downloaded CVE's from the NVD database into memory.
213-
func loadAllCVEs(cvePath string) map[cves.CVEID]cves.Vulnerability {
214-
dir, err := os.ReadDir(cvePath)
215-
if err != nil {
216-
logger.Fatal("Failed to read dir", slog.String("path", cvePath), slog.Any("err", err))
217-
}
218-
219-
result := make(map[cves.CVEID]cves.Vulnerability)
220-
221-
for _, entry := range dir {
222-
if !strings.HasSuffix(entry.Name(), ".json") {
223-
continue
224-
}
225-
file, err := os.Open(path.Join(cvePath, entry.Name()))
226-
if err != nil {
227-
logger.Fatal("Failed to open CVE JSON", slog.String("path", path.Join(cvePath, entry.Name())), slog.Any("err", err))
228-
}
229-
var nvdcve cves.CVEAPIJSON20Schema
230-
err = json.NewDecoder(file).Decode(&nvdcve)
231-
if err != nil {
232-
logger.Fatal("Failed to decode JSON", slog.String("file", file.Name()), slog.Any("err", err))
233-
}
234-
235-
for _, item := range nvdcve.Vulnerabilities {
236-
result[item.CVE.ID] = item
237-
}
238-
logger.Info("Loaded CVE "+entry.Name(), slog.String("cve", entry.Name()))
239-
file.Close()
240-
}
241-
242-
return result
243-
}
244-
245206
// addReference adds the related security tracker URL to a given vulnerability's references
246207
func addReference(cveID string, ecosystem string, convertedCve *vulns.Vulnerability) {
247208
securityReference := osvschema.Reference{Type: osvschema.ReferenceAdvisory}
248-
switch ecosystem {
249-
case alpineEcosystem:
209+
if ecosystem == alpineEcosystem {
250210
securityReference.URL, _ = url.JoinPath(alpineSecurityTrackerURL, cveID)
251-
case debianEcosystem:
252-
securityReference.URL, _ = url.JoinPath(debianSecurityTrackerURL, cveID)
253211
}
254212

255213
if securityReference.URL == "" {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,14 @@ func TestCombineIntoOSV(t *testing.T) {
104104
if len(combinedOSV[cve].Affected) != len(allParts[cve]) {
105105
t.Errorf("Affected lengths for %s do not match", cve)
106106
}
107+
107108
found := false
108109
switch cve {
109110
case "CVE-2018-1000500":
110111
for _, reference := range combinedOSV[cve].References {
111112
if reference.Type == "ADVISORY" &&
112113
reference.URL == "https://security-tracker.debian.org/tracker/CVE-2018-1000500" {
113-
found = true
114+
t.Errorf("Found unexpected Debian advisory URL for %s", cve)
114115
}
115116
}
116117
case "CVE-2022-33745":
@@ -128,12 +129,11 @@ func TestCombineIntoOSV(t *testing.T) {
128129
}
129130
}
130131
}
131-
if !found {
132+
if !found && cve != "CVE-2018-1000500" {
132133
t.Errorf("%s doesn't have all expected references", cve)
133134
}
134135
}
135136
}
136-
137137
func TestGetModifiedTime(t *testing.T) {
138138
_, err := getModifiedTime("../../test_data/parts/debian/CVE-2016-1585.debian.json")
139139
if err != nil {

vulnfeeds/cmd/debian/debian_security_tracker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ type Release struct {
77
Urgency string `json:"urgency"`
88
}
99

10-
type CVE struct {
10+
type DebianCVE struct {
1111
Description string `json:"description"`
1212
DebianBug int
1313
Scope string `json:"scope"`
1414
Releases map[string]Release `json:"releases"`
1515
}
1616

17-
type DebianSecurityTrackerData map[string]map[string]CVE
17+
type DebianSecurityTrackerData map[string]map[string]DebianCVE

0 commit comments

Comments
 (0)