Skip to content

Commit 2a4dfbf

Browse files
fix(cyclonedx): include CVSS v4 vulnerability ratings (aquasecurity#10313)
Co-authored-by: DmitriyLewen <dmitriy.lewen@smartforce.io>
1 parent 77f5cb5 commit 2a4dfbf

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

pkg/sbom/cyclonedx/marshal.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ func (m *Marshaler) ratings(vuln core.Vulnerability) *[]cdx.VulnerabilityRating
488488
if cvss.V3Score != 0 || cvss.V3Vector != "" {
489489
rates = append(rates, m.ratingV3(sourceID, severity, cvss))
490490
}
491+
if cvss.V40Score != 0 || cvss.V40Vector != "" {
492+
rates = append(rates, m.ratingV4(sourceID, severity, cvss))
493+
}
491494
} else { // When the vendor provides only severity
492495
rate := cdx.VulnerabilityRating{
493496
Source: &cdx.Source{
@@ -550,6 +553,18 @@ func (m *Marshaler) ratingV3(sourceID dtypes.SourceID, severity dtypes.Severity,
550553
return rate
551554
}
552555

556+
func (m *Marshaler) ratingV4(sourceID dtypes.SourceID, severity dtypes.Severity, cvss dtypes.CVSS) cdx.VulnerabilityRating {
557+
return cdx.VulnerabilityRating{
558+
Source: &cdx.Source{
559+
Name: string(sourceID),
560+
},
561+
Score: &cvss.V40Score,
562+
Method: cdx.ScoringMethodCVSSv4,
563+
Severity: m.severity(severity),
564+
Vector: cvss.V40Vector,
565+
}
566+
}
567+
553568
// severity converts the Trivy severity to the CycloneDX severity
554569
func (*Marshaler) severity(s dtypes.Severity) cdx.Severity {
555570
switch s {

pkg/sbom/cyclonedx/marshal_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,8 +1567,10 @@ func TestMarshaler_MarshalReport(t *testing.T) {
15671567
},
15681568
CVSS: dtypes.VendorCVSS{
15691569
vulnerability.GHSA: dtypes.CVSS{
1570-
V3Vector: "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
1571-
V3Score: 7.5,
1570+
V3Vector: "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
1571+
V3Score: 7.5,
1572+
V40Vector: "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N",
1573+
V40Score: 8.7,
15721574
},
15731575
},
15741576
References: []string{
@@ -1655,6 +1657,15 @@ func TestMarshaler_MarshalReport(t *testing.T) {
16551657
Method: cdx.ScoringMethodCVSSv31,
16561658
Vector: "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
16571659
},
1660+
{
1661+
Source: &cdx.Source{
1662+
Name: string(vulnerability.GHSA),
1663+
},
1664+
Score: lo.ToPtr(8.7),
1665+
Severity: cdx.SeverityHigh,
1666+
Method: cdx.ScoringMethodCVSSv4,
1667+
Vector: "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N",
1668+
},
16581669
},
16591670
Description: "In FasterXML jackson-databind before versions 2.13.4.1 and 2.12.17.1, resource exhaustion can occur because of a lack of a check in primitive value deserializers to avoid deep wrapper array nesting, when the UNWRAP_SINGLE_VALUE_ARRAYS feature is enabled.",
16601671
Advisories: &[]cdx.Advisory{

0 commit comments

Comments
 (0)