Skip to content

Commit 6e4c348

Browse files
committed
adds debugLocalZip support, stops removing cves
1 parent eb3041b commit 6e4c348

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

transformer/osv_transformer.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,13 @@ func AffectedComponentsFromOSV(osv *dtos.OSV) []models.AffectedComponent {
106106
affectedComponents := make([]models.AffectedComponent, 0, len(osv.Affected)*3)
107107

108108
for _, affected := range osv.Affected {
109-
if affected.EcosystemSpecific != nil {
109+
// we should not remove affected components - otherwise it might happen, that we remove a vulnerability from the database (check runCleanupJobs) and therefore lose the append only property of this database - which makes it so fast and simple currently.
110+
/*if affected.EcosystemSpecific != nil {
110111
// debian defines urgency: https://security-team.debian.org/security_tracker.html#severity-levels
111-
if affected.EcosystemSpecific.Urgency == "unimportant" {
112-
continue
112+
affected.EcosystemSpecific.Urgency == "unimportant" {
113+
// continue
113114
}
114-
}
115+
}*/
115116

116117
if affected.Package.Purl != "" {
117118
affectedComponents = append(affectedComponents, affectedComponentsFromAffected(affected)...)

vulndb/osv_service.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23+
"io"
2324
"log/slog"
2425
"net/http"
26+
"os"
2527
"slices"
2628
"strings"
2729
"sync"
@@ -103,6 +105,7 @@ type zipJob struct {
103105
}
104106

105107
const numberOfZipWorkers = 10
108+
const debugLocalZip = false // set to true to read the zip files from disk instead of fetching them from the network; useful for debugging and development to speed up the import process
106109

107110
var deduplicateCveMap = sync.Map{} // map[string]struct{} to track already processed CVE IDs and avoid duplicates
108111

@@ -287,6 +290,21 @@ func (s osvService) fetchEcosystemEntriesViaZip(zipPushWaitGroup *sync.WaitGroup
287290
}
288291

289292
func (s osvService) getOSVZipContainingEcosystem(ecosystem string) (*zip.Reader, error) {
293+
if debugLocalZip {
294+
slog.Info("debug mode enabled, reading zip from disk instead of fetching from network", "ecosystem", ecosystem)
295+
// check if the file exists on disk and read it if it does, otherwise return an error
296+
path := fmt.Sprintf("./%s.zip", ecosystem)
297+
if _, err := os.Stat(path); err != nil {
298+
// just fall through to download it
299+
slog.Warn("could not find local zip file, falling back to network fetch", "path", path)
300+
} else {
301+
reader, err := zip.OpenReader(path)
302+
if err == nil {
303+
slog.Info("successfully opened local zip file", "path", path)
304+
return &reader.Reader, nil
305+
}
306+
}
307+
}
290308
req, err := http.NewRequest(http.MethodGet, osvBaseURL+"/"+ecosystem+"/all.zip", nil)
291309
if err != nil {
292310
return nil, errors.Wrap(err, "could not create request")
@@ -296,6 +314,18 @@ func (s osvService) getOSVZipContainingEcosystem(ecosystem string) (*zip.Reader,
296314
if err != nil {
297315
return nil, errors.Wrap(err, "could not download zip")
298316
}
317+
if debugLocalZip {
318+
// use a tee reader to read the response body and write it to a file at the same time for debugging purposes
319+
path := fmt.Sprintf("./%s.zip", ecosystem)
320+
outFile, err := os.Create(path)
321+
if err != nil {
322+
slog.Warn("could not create local zip file, skipping writing to disk", "path", path, "err", err)
323+
} else {
324+
slog.Info("created local zip file for debugging", "path", path)
325+
tee := io.TeeReader(res.Body, outFile)
326+
res.Body = io.NopCloser(tee)
327+
}
328+
}
299329

300330
return utils.ZipReaderFromResponse(res)
301331
}

0 commit comments

Comments
 (0)