Skip to content

Commit

Permalink
prefer nvd score if both nvd and vendor cvss v3 scores exist (#1080)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulchinsky authored Mar 21, 2023
1 parent eec5594 commit f57815e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/plugins/trivy/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2069,11 +2069,11 @@ func GetScoreFromCVSS(CVSSs map[string]*CVSS) *float64 {
}
}

if vendorScore != nil {
return vendorScore
if nvdScore != nil {
return nvdScore
}

return nvdScore
return vendorScore
}

func GetMirroredImage(image string, mirrors map[string]string) (string, error) {
Expand Down
13 changes: 11 additions & 2 deletions pkg/plugins/trivy/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6673,7 +6673,7 @@ func TestGetScoreFromCVSS(t *testing.T) {
expectedScore *float64
}{
{
name: "Should return vendor score when vendor v3 score exist",
name: "Should return nvd score when nvd and vendor v3 score exist",
cvss: dbtypes.VendorCVSS{
"nvd": {
V3Score: 8.1,
Expand All @@ -6682,7 +6682,7 @@ func TestGetScoreFromCVSS(t *testing.T) {
V3Score: 8.3,
},
},
expectedScore: pointer.Float64(8.3),
expectedScore: pointer.Float64(8.1),
},
{
name: "Should return nvd score when vendor v3 score is nil",
Expand All @@ -6705,6 +6705,15 @@ func TestGetScoreFromCVSS(t *testing.T) {
},
expectedScore: pointer.Float64(8.1),
},
{
name: "Should return vendor score when nvd doesn't exist",
cvss: dbtypes.VendorCVSS{
"redhat": {
V3Score: 8.1,
},
},
expectedScore: pointer.Float64(8.1),
},
{
name: "Should return nil when vendor and nvd both v3 scores are nil",
cvss: dbtypes.VendorCVSS{
Expand Down

0 comments on commit f57815e

Please sign in to comment.