Skip to content

Commit

Permalink
add rejected vulnerability check for redhat
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen committed Aug 2, 2022
1 parent 3e1814e commit fcea559
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/vulndb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (t TrivyDB) optimize() error {
// This bucket has only vulnerability IDs provided by vendors. They must be stored.
err := t.dbc.ForEachVulnerabilityID(func(tx *bolt.Tx, cveID string) error {
details := t.vulnClient.GetDetails(cveID)
if t.vulnClient.IsRejected(details) {
if vulnerability.IsRejected(details) {
return nil
}

Expand Down
19 changes: 14 additions & 5 deletions pkg/vulnsrc/redhat-oval/redhat-oval.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (vs VulnSrc) Update(dir string) error {
continue
}

definitions, err := parseOVALStream(filepath.Join(versionDir, f.Name()), uniqCPEs)
definitions, err := vs.parseOVALStream(filepath.Join(versionDir, f.Name()), uniqCPEs)
if err != nil {
return xerrors.Errorf("failed to parse OVAL stream: %w", err)
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func (vs VulnSrc) Get(pkgName string, repositories, nvrs []string) ([]types.Advi
return advisories, nil
}

func parseOVALStream(dir string, uniqCPEs CPEMap) (map[bucket]Definition, error) {
func (vs VulnSrc) parseOVALStream(dir string, uniqCPEs CPEMap) (map[bucket]Definition, error) {
log.Printf(" Parsing %s", dir)

// Parse tests
Expand Down Expand Up @@ -316,10 +316,10 @@ func parseOVALStream(dir string, uniqCPEs CPEMap) (map[bucket]Definition, error)
return nil, xerrors.Errorf("Red Hat OVAL walk error: %w", err)
}

return parseDefinitions(advisories, tests, uniqCPEs), nil
return vs.parseDefinitions(advisories, tests, uniqCPEs)
}

func parseDefinitions(advisories []redhatOVAL, tests map[string]rpmInfoTest, uniqCPEs CPEMap) map[bucket]Definition {
func (vs VulnSrc) parseDefinitions(advisories []redhatOVAL, tests map[string]rpmInfoTest, uniqCPEs CPEMap) (map[bucket]Definition, error) {
defs := map[bucket]Definition{}

for _, advisory := range advisories {
Expand All @@ -342,6 +342,15 @@ func parseDefinitions(advisories []redhatOVAL, tests map[string]rpmInfoTest, uni

var cveEntries []CveEntry
for _, cve := range advisory.Metadata.Advisory.Cves {
// get details from NVD
details, err := vs.dbc.GetVulnerabilityDetail(cve.CveID)
if err != nil {
return nil, xerrors.Errorf("Failed to get vulnerability detail: %s", err)
}
// don't use rejected vulnerabilities
if vulnerability.IsRejected(details) {
continue
}
cveEntries = append(cveEntries, CveEntry{
ID: cve.CveID,
Severity: severityFromImpact(cve.Impact),
Expand Down Expand Up @@ -386,7 +395,7 @@ func parseDefinitions(advisories []redhatOVAL, tests map[string]rpmInfoTest, uni
updateCPEs(advisory.Metadata.Advisory.AffectedCpeList, uniqCPEs)
}

return defs
return defs, nil
}

func walkCriterion(cri criteria, tests map[string]rpmInfoTest) (string, []pkg) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/vulnerability/vulnerability.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (v Vulnerability) GetDetails(vulnID string) map[types.SourceID]types.Vulner
return details
}

func (Vulnerability) IsRejected(details map[types.SourceID]types.VulnerabilityDetail) bool {
func IsRejected(details map[types.SourceID]types.VulnerabilityDetail) bool {
return getRejectedStatus(details)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/vulnsrc/vulnerability/vulnerability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestIsRejected(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := vulnerability.New(nil).IsRejected(tc.details)
got := vulnerability.IsRejected(tc.details)
assert.Equal(t, tc.want, got)
})
}
Expand Down

0 comments on commit fcea559

Please sign in to comment.