Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add AllSourceIDs #485

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion pkg/vulnsrc/vulnerability/const.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package vulnerability

import "github.com/aquasecurity/trivy-db/pkg/types"
import (
"github.com/aquasecurity/trivy-db/pkg/types"
)

const (
// Data source
Expand Down Expand Up @@ -70,3 +72,38 @@ var Ecosystems = []types.Ecosystem{
Bitnami,
Kubernetes,
}

// AllSourceIDs lists all supported vulnerability source IDs in order of precedence.
// When searching for vulnerability details (Severity, Title, Description, and CWE-IDs),
// the sources are checked in this order until valid data is found.
// For example, if severity data is missing in NVD, it will check Red Hat next,
// continuing through the list until it finds a valid severity value.
var AllSourceIDs = []types.SourceID{
NVD,
RedHat,
RedHatOVAL,
Debian,
Ubuntu,
Alpine,
Amazon,
OracleOVAL,
SuseCVRF,
Photon,
ArchLinux,
Alma,
Rocky,
CBLMariner,
AzureLinux,
RubySec,
PhpSecurityAdvisories,
NodejsSecurityWg,
GHSA,
GLAD,
Aqua,
OSV,
K8sVulnDB,
Wolfi,
Chainguard,
BitnamiVulndb,
GoVulnDB,
}
20 changes: 6 additions & 14 deletions pkg/vulnsrc/vulnerability/vulnerability.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ const (
rejectVulnerability = "** REJECT **"
)

var (
sources = []types.SourceID{
NVD, RedHat, Debian, Ubuntu, Alpine, Amazon, OracleOVAL, SuseCVRF, Photon,
ArchLinux, Alma, Rocky, CBLMariner, AzureLinux, RubySec, PhpSecurityAdvisories, NodejsSecurityWg, GHSA, GLAD,
Aqua, OSV, K8sVulnDB,
}
)

type Vulnerability struct {
dbc db.Operation
}
Expand Down Expand Up @@ -98,7 +90,7 @@ func getVendorSeverity(details map[types.SourceID]types.VulnerabilityDetail) typ
}

func getSeverity(details map[types.SourceID]types.VulnerabilityDetail) types.Severity {
for _, source := range sources {
for _, source := range AllSourceIDs {
switch d, ok := details[source]; {
case !ok:
continue
Expand All @@ -120,7 +112,7 @@ func getSeverity(details map[types.SourceID]types.VulnerabilityDetail) types.Sev
}

func getTitle(details map[types.SourceID]types.VulnerabilityDetail) string {
for _, source := range sources {
for _, source := range AllSourceIDs {
d, ok := details[source]
if !ok {
continue
Expand All @@ -133,7 +125,7 @@ func getTitle(details map[types.SourceID]types.VulnerabilityDetail) string {
}

func getDescription(details map[types.SourceID]types.VulnerabilityDetail) string {
for _, source := range sources {
for _, source := range AllSourceIDs {
d, ok := details[source]
if !ok {
continue
Expand All @@ -146,7 +138,7 @@ func getDescription(details map[types.SourceID]types.VulnerabilityDetail) string
}

func getCweIDs(details map[types.SourceID]types.VulnerabilityDetail) []string {
for _, source := range sources {
for _, source := range AllSourceIDs {
d, ok := details[source]
if !ok {
continue
Expand All @@ -160,7 +152,7 @@ func getCweIDs(details map[types.SourceID]types.VulnerabilityDetail) []string {

func getReferences(details map[types.SourceID]types.VulnerabilityDetail) []string {
references := map[string]struct{}{}
for _, source := range sources {
for _, source := range AllSourceIDs {
// Amazon contains unrelated references
if source == Amazon {
continue
Expand Down Expand Up @@ -188,7 +180,7 @@ func getReferences(details map[types.SourceID]types.VulnerabilityDetail) []strin
}

func getRejectedStatus(details map[types.SourceID]types.VulnerabilityDetail) bool {
for _, source := range sources {
for _, source := range AllSourceIDs {
d, ok := details[source]
if !ok {
continue
Expand Down
Loading