Description
CycloneDX supports 3 possible fields for licenses:
multiple licenses by ID - https://cyclonedx.org/docs/1.6/json/#tab-pane_components_items_licenses_oneOf_i0_items_license_oneOf_i0
multiple licenses by Name - https://cyclonedx.org/docs/1.6/json/#tab-pane_components_items_licenses_oneOf_i0_items_license_oneOf_i1
SPDX license expression - https://cyclonedx.org/docs/1.6/json/#tab-pane_components_items_licenses_oneOf_i1
We added handaling for SPDX licenses - #8077 .
But we don't use similar logic for CycloneDX reports.
We use 2 way (licenses by Name) for all licenses:
License : & cdx.License {
Name : license ,
},
But there are case when this is incorrect:
when license is SPDX license ID, but we use name instead of id
when license is SPDX expression (see Unofficial License Names in CycloneDX SBOMs #9033 ).
Solution
We need to parse each got license before insert in in CycloneDX report:
for single license:
1.2. check that this is SPDX license. Use ID field for SPDX license and name for another license.
for multiple licenses
2.1. Use SPDX expression for valid SPDX expression
2.2.for other cases split licenses and use name/id field for each license
Discussed in #9033
Description
CycloneDX supports 3 possible fields for licenses:
We added handaling for SPDX licenses - #8077.
But we don't use similar logic for CycloneDX reports.
We use 2 way (licenses by Name) for all licenses:
trivy/pkg/sbom/cyclonedx/marshal.go
Lines 290 to 292 in 454b894
But there are case when this is incorrect:
nameinstead ofidSolution
We need to parse each got license before insert in in CycloneDX report:
1.2. check that this is SPDX license. Use
IDfield for SPDX license andnamefor another license.2.1. Use
SPDX expressionfor valid SPDX expression2.2.for other cases split licenses and use
name/idfield for each licenseDiscussed in #9033