Repository navigation
fix(sbom): keep every detected component version in CycloneDX and SPDX - #228
Merged
Merged
Conversation
SCANOSS SCAN Completed 🚀
View more details on SCANOSS Action Summary |
SCANOSS SCAN Completed 🚀
View more details on SCANOSS Action Summary |
SCANOSS SCAN Completed 🚀
View more details on SCANOSS Action Summary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #226
Fixes #229
Problem
The CycloneDX and SPDX Lite converters keyed components by the versionless purl and skipped any purl already stored. When files matched several releases of the same component, only the first version encountered survived, while the default JSON output kept them all. Which version won depended on result order, so separate scans of the same code could report different versions. In CycloneDX, vulnerabilities from every version were also attached to the single surviving component.
Changes
utils/purl.py):versioned_purl(purl, version)pins a purl to the detected version usingPackageURL. Purls that already carry a version, entries without a version, and unparsable purls are returned unchanged, and the version is placed before any qualifiers. Both converters use it, so CycloneDX and SPDX always produce the same versioned purl.cyclonedx.py): components are keyed by the versioned purl, which is also thebom-ref. The componentpurlfield is unchanged (versionless). Vulnerabilityaffectsrefs use the same key, so each CVE points at the version it was reported on.spdxlite.py): summaries are keyed by the versioned purl, so each version becomes its own package. This also fixes two existing edge cases in the package purl: a purl that already had a version was pinned twice (pkg:npm/lodash%404.17.21@4.17.21), and a missing version producedpkg:npm/lodash@None. SPDX IDs are unchanged for normal input.scanner_hfh.py):append_vulnerabilitiesnow receives the component'sbom-ref(parameter renamedpurl→bom_ref), otherwise the appended vulnerabilities would reference a component that no longer exists.tests/test_spdxlite.py:tests/data/result.jsoncontainsscanner.cat 1.3.3 and 1.1.4 andengineat 5.4.0 and 4.0.4, so the expected package count goes from 6 to 8.Behaviour change: CycloneDX
bom-refis nowpurl@versionfor every component, not only multi-version ones. Noted in the CHANGELOG.Verification
python -m unittest): 344 run, OK, 1 skipped.tests/test_sbom_multi_version.py: one entry per version in both formats, uniquebom-refs and SPDX IDs, vulnerabilities referencing their own version, CycloneDX schema validation, the purl request built from a CycloneDX file, and both formats producing the same purls for edge cases.tests/test_purl.py:versioned_purlwith versionless, already-versioned, encoded and qualified purls, missing, numeric and commit-hash versions, and unparsable input.make lintis clean on the changed files apart fromscanner_hfh.pyPLR0917, which is already present onmain.main(1.54.2)pkg:github/signalwire/freeswitchv1.6.7onlyv1.6.7,v1.6.8pkg:github/begeekmyfriend/yaseapkg:github/lllllt/multipicturelivewallpaperpkg:github/google/ringdroid,danielhk/android_frameworks_av_mtk,uizaio/uiza-android-sdk-playerbom-refs / SPDX IDs uniqueaffectsrefs resolve to a componentdocumentDescribesmatches packagesscan --wfprun with-f cyclonedxand-f spdxlitekeeps every multi-version component in both SBOMs. Separate scans can still differ slightly when the server returns a different match for a file between runs (for example a short versus a full commit hash), but each SBOM now reflects all versions in its own scan.Container build (#229)
Separate commit, unrelated to the SBOM change: the container image stopped building because
scancode-toolkit-mininow pullspluggy1.7.0, whichplugincode32.0.0 cannot register hooks with. The Dockerfile pinspluggy<1.7next to the existingclickworkaround. Reproduced in a clean environment: importingplugincode.pre_scanfails with pluggy 1.7.0 and works with 1.6.0.Release
Bumps the version to 1.54.3 and moves the CHANGELOG entries under
[1.54.3].Notes
purlfield unchanged, soget_purls_request_from_cdxkeeps sending a versionless purl with arequirement.