Repository navigation
fix(sbom): keep every detected component version in the SPDX Lite and CycloneDX converters - #227
Closed
rahul05ranjan wants to merge 1 commit into
Closed
rahul05ranjan wants to merge 1 commit into
rahul05ranjan wants to merge 1 commit into
Conversation
… CycloneDX converters Raw scan results carry versionless purls; the detected version lives in the entry's version field. Both converters keyed their summaries by that bare purl and skipped any purl already stored, so when the same component was detected at several versions only the first survived, while the Default JSON output kept them all. Key both converters by the purl with the detected version attached (unchanged for purls that already carry one, or entries with no version). CycloneDX vulnerability affects refs use the same key, so they keep pointing at the component they were reported for, and component purl/bom-ref stay consistent with it. Fixes scanoss#226 Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
Contributor
|
Hi @rahul05ranjan, thanks a lot for this, and sorry for the overlap. We had been working on the same issue internally and opened #228, which also fixes the vulnerability refs in the folder-hash output, shares the purl helper between both converters, and is part of the 1.54.3 release. Your PR was a useful cross-check, especially the qualifier handling, which we picked up as well. I'll close this one in favour of #228. Thanks again, and contributions are always welcome! |
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.
Raw scan results carry versionless purls — the detected version lives in the entry's
versionfield. Both converters keyed their summaries by that bare purl and skipped any purl already stored ("Component … already stored"), so when the same component was detected at several versions, only the first survived in SPDX Lite and CycloneDX output, while the Default JSON kept them all. The repo's owntests/data/result.jsonshows it directly:scanner.cis detected at 1.3.3 and 1.1.4,engineat 5.4.0 and 4.0.4 — the old assertions of 6 packages were counting the bug.Change: both converters now key by the purl with the detected version attached (
_versioned_purl): versionless purl + entry version →purl@version; purls that already carry a version (only the part before?is inspected, so qualifiers are left alone) and entries with no version keep the old key, so genuine duplicates still deduplicate. Consequences, all deliberate:SPDXID,versionInfoand purlreferenceLocator(the package purl is the samepurl@versionstring the old code already produced for the first version).purlandbom-refare the versioned purl, which is the recommended bom-ref shape.affectsrefs now use the same versioned key, so they keep matching the components they were reported for (a CVE listed on both files' entries affects both versions).Verification. This host has no
packageurl/importlib_resources/cyclonedx-python-libinstalls available, so I could not runmake unit_testas-is; instead I ran the suite through a small harness that stubs exactly those third-party imports (python -m unittestdiscovery overtests/test_spdxlite.py+ the newtests/test_sbom_component_versions.py): 22 tests, all pass — the 14 existing SPDX Lite tests (with the 6→8 counts updated forresult.json's two extra versions) and 8 new tests covering: both versions kept by each converter, one SPDX package per version with distinct IDs, same-version duplicates still deduped, versioned purls untouched, missing version falling back to the bare purl, and vulnerability affects covering both versions when reported on both. Before the change, the twoparsetests see exactly one component where two are expected. In CI (python -m unittest, real deps) these run unmodified.