Skip to content

Commit

Permalink
feat(trivy): support CVSS v4.0 (future-architect#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaineK00n authored Aug 8, 2024
1 parent b2d4eaf commit f14ca86
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
24 changes: 15 additions & 9 deletions contrib/trivy/parser/v2/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ var oneCVEtoNVulnerabilityTrivy = []byte(`
],
"VendorSeverity": {
"ghsa": 2,
"nvd": 2,
"nvd": 3,
"ruby-advisory-db": 2
},
"CVSS": {
Expand All @@ -1958,6 +1958,8 @@ var oneCVEtoNVulnerabilityTrivy = []byte(`
"V3Score": 5.9
},
"nvd": {
"V40Vector": "CVSS:4.0/AV:N/AC:H/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:H/SI:N/SA:N",
"V40Score": 8.9,
"V3Vector": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N",
"V3Score": 5.9
}
Expand Down Expand Up @@ -2027,7 +2029,7 @@ var oneCVEtoNVulnerabilityTrivy = []byte(`
],
"VendorSeverity": {
"ghsa": 2,
"nvd": 2,
"nvd": 3,
"ruby-advisory-db": 2
},
"CVSS": {
Expand All @@ -2036,6 +2038,8 @@ var oneCVEtoNVulnerabilityTrivy = []byte(`
"V3Score": 5.9
},
"nvd": {
"V40Vector": "CVSS:4.0/AV:N/AC:H/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:H/SI:N/SA:N",
"V40Score": 8.9,
"V3Vector": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N",
"V3Score": 5.9
}
Expand Down Expand Up @@ -2545,7 +2549,7 @@ var oneCVEtoNVulnerabilitySR = &models.ScanResult{
CveID: "CVE-2023-26154",
Title: "pubnub Insufficient Entropy vulnerability",
Summary: "Versions of the package pubnub before 7.4.0; all versions of the package com.pubnub:pubnub; versions of the package pubnub before 6.19.0; all versions of the package github.com/pubnub/go; versions of the package github.com/pubnub/go/v7 before 7.2.0; versions of the package pubnub before 7.3.0; versions of the package pubnub/pubnub before 6.1.0; versions of the package pubnub before 5.3.0; versions of the package pubnub before 0.4.0; versions of the package pubnub/c-core before 4.5.0; versions of the package com.pubnub:pubnub-kotlin before 7.7.0; versions of the package pubnub/swift before 6.2.0; versions of the package pubnub before 5.2.0; versions of the package pubnub before 4.3.0 are vulnerable to Insufficient Entropy via the getKey function, due to inefficient implementation of the AES-256-CBC cryptographic algorithm. The provided encrypt function is less secure when hex encoding and trimming are applied, leaving half of the bits in the key always the same for every encoded message or file.\r\r**Note:**\r\rIn order to exploit this vulnerability, the attacker needs to invest resources in preparing the attack and brute-force the encryption.",
Cvss3Severity: "MEDIUM",
Cvss3Severity: "HIGH",
References: models.References{
{
Source: "trivy",
Expand Down Expand Up @@ -2648,12 +2652,14 @@ var oneCVEtoNVulnerabilitySR = &models.ScanResult{
LastModified: time.Date(2023, time.December, 11, 17, 48, 3, 653, time.UTC),
},
{
Type: "trivy:nvd",
CveID: "CVE-2023-26154",
Title: "pubnub Insufficient Entropy vulnerability",
Summary: "Versions of the package pubnub before 7.4.0; all versions of the package com.pubnub:pubnub; versions of the package pubnub before 6.19.0; all versions of the package github.com/pubnub/go; versions of the package github.com/pubnub/go/v7 before 7.2.0; versions of the package pubnub before 7.3.0; versions of the package pubnub/pubnub before 6.1.0; versions of the package pubnub before 5.3.0; versions of the package pubnub before 0.4.0; versions of the package pubnub/c-core before 4.5.0; versions of the package com.pubnub:pubnub-kotlin before 7.7.0; versions of the package pubnub/swift before 6.2.0; versions of the package pubnub before 5.2.0; versions of the package pubnub before 4.3.0 are vulnerable to Insufficient Entropy via the getKey function, due to inefficient implementation of the AES-256-CBC cryptographic algorithm. The provided encrypt function is less secure when hex encoding and trimming are applied, leaving half of the bits in the key always the same for every encoded message or file.\r\r**Note:**\r\rIn order to exploit this vulnerability, the attacker needs to invest resources in preparing the attack and brute-force the encryption.",
Cvss3Score: 5.9,
Cvss3Vector: "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N",
Type: "trivy:nvd",
CveID: "CVE-2023-26154",
Title: "pubnub Insufficient Entropy vulnerability",
Summary: "Versions of the package pubnub before 7.4.0; all versions of the package com.pubnub:pubnub; versions of the package pubnub before 6.19.0; all versions of the package github.com/pubnub/go; versions of the package github.com/pubnub/go/v7 before 7.2.0; versions of the package pubnub before 7.3.0; versions of the package pubnub/pubnub before 6.1.0; versions of the package pubnub before 5.3.0; versions of the package pubnub before 0.4.0; versions of the package pubnub/c-core before 4.5.0; versions of the package com.pubnub:pubnub-kotlin before 7.7.0; versions of the package pubnub/swift before 6.2.0; versions of the package pubnub before 5.2.0; versions of the package pubnub before 4.3.0 are vulnerable to Insufficient Entropy via the getKey function, due to inefficient implementation of the AES-256-CBC cryptographic algorithm. The provided encrypt function is less secure when hex encoding and trimming are applied, leaving half of the bits in the key always the same for every encoded message or file.\r\r**Note:**\r\rIn order to exploit this vulnerability, the attacker needs to invest resources in preparing the attack and brute-force the encryption.",
Cvss3Score: 5.9,
Cvss3Vector: "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N",
Cvss40Score: 8.9,
Cvss40Vector: "CVSS:4.0/AV:N/AC:H/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:H/SI:N/SA:N",
References: models.References{
{
Source: "trivy",
Expand Down
7 changes: 4 additions & 3 deletions contrib/trivy/pkg/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ func Convert(results types.Results) (result *models.ScanResult, err error) {
}
}
}
slices.SortFunc(severities, trivydbTypes.CompareSeverityString)
slices.Reverse(severities)
slices.SortFunc(severities, func(a, b string) int { return -trivydbTypes.CompareSeverityString(a, b) })

vulnInfo.CveContents[models.CveContentType(fmt.Sprintf("%s:%s", models.Trivy, source))] = []models.CveContent{{
Type: models.CveContentType(fmt.Sprintf("%s:%s", models.Trivy, source)),
Expand All @@ -100,7 +99,7 @@ func Convert(results types.Results) (result *models.ScanResult, err error) {
for source, cvss := range vuln.CVSS {
if cs, ok := vulnInfo.CveContents[models.CveContentType(fmt.Sprintf("%s:%s", models.Trivy, source))]; ok &&
slices.ContainsFunc(cs, func(c models.CveContent) bool {
return c.Cvss2Score == cvss.V2Score && c.Cvss2Vector == cvss.V2Vector && c.Cvss3Score == cvss.V3Score && c.Cvss3Vector == cvss.V3Vector
return c.Cvss2Score == cvss.V2Score && c.Cvss2Vector == cvss.V2Vector && c.Cvss3Score == cvss.V3Score && c.Cvss3Vector == cvss.V3Vector && c.Cvss40Score == cvss.V40Score && c.Cvss40Vector == cvss.V40Vector
}) {
continue
}
Expand All @@ -114,6 +113,8 @@ func Convert(results types.Results) (result *models.ScanResult, err error) {
Cvss2Vector: cvss.V2Vector,
Cvss3Score: cvss.V3Score,
Cvss3Vector: cvss.V3Vector,
Cvss40Score: cvss.V40Score,
Cvss40Vector: cvss.V40Vector,
Published: published,
LastModified: lastModified,
References: references,
Expand Down
18 changes: 10 additions & 8 deletions detector/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,16 @@ func getCveContents(cveID string, vul trivydbTypes.Vulnerability) (contents map[

for source, cvss := range vul.CVSS {
contents[models.CveContentType(fmt.Sprintf("%s:%s", models.Trivy, source))] = append(contents[models.CveContentType(fmt.Sprintf("%s:%s", models.Trivy, source))], models.CveContent{
Type: models.CveContentType(fmt.Sprintf("%s:%s", models.Trivy, source)),
CveID: cveID,
Title: vul.Title,
Summary: vul.Description,
Cvss2Score: cvss.V2Score,
Cvss2Vector: cvss.V2Vector,
Cvss3Score: cvss.V3Score,
Cvss3Vector: cvss.V3Vector,
Type: models.CveContentType(fmt.Sprintf("%s:%s", models.Trivy, source)),
CveID: cveID,
Title: vul.Title,
Summary: vul.Description,
Cvss2Score: cvss.V2Score,
Cvss2Vector: cvss.V2Vector,
Cvss3Score: cvss.V3Score,
Cvss3Vector: cvss.V3Vector,
Cvss40Score: cvss.V40Score,
Cvss40Vector: cvss.V40Vector,
Published: func() time.Time {
if vul.PublishedDate != nil {
return *vul.PublishedDate
Expand Down

0 comments on commit f14ca86

Please sign in to comment.