feat(cyclonedx): use evidence.occurrences for file paths instead of FilePath property#10937
Open
kevglynn wants to merge 1 commit into
Open
feat(cyclonedx): use evidence.occurrences for file paths instead of FilePath property#10937kevglynn wants to merge 1 commit into
kevglynn wants to merge 1 commit into
Conversation
…ilePath property CycloneDX has a native field for recording where a component was found: evidence.occurrences. Use it in CycloneDX output instead of the proprietary aquasecurity:trivy:FilePath property. The aquasecurity:trivy:FilePath property is still parsed when scanning SBOMs generated by older versions of Trivy. Close aquasecurity#9832 Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Description
CycloneDX has a native field for recording where a component was found:
evidence.occurrences(available since spec 1.5). Trivy currently records this in a proprietaryaquasecurity:trivy:FilePathproperty instead.This PR switches CycloneDX output to
evidence.occurrences:pkg/sbom/io/encode.go: no longer adds theFilePathproperty to component properties (the file path is already carried incore.Component.Files).pkg/sbom/cyclonedx/marshal.go: marshalscore.Component.Filespaths asevidence.occurrences[].location.pkg/sbom/cyclonedx/unmarshal.go: parsesevidence.occurrencesback intocore.Component.Files, so re-scanning a Trivy SBOM preserves file paths.Backward compatibility
pkg/sbom/io/decode.gostill parses theaquasecurity:trivy:FilePathproperty, so SBOMs generated by older versions of Trivy keep working. Existing test fixtures using the old property (testdata/happy/bom.json,testdata/happy/group-in-name.json, fanal SBOM testdata, and thefluentd-multiple-lockfiles-cyclonedx.jsonintegration fixture) are intentionally left unchanged so they keep covering this path.testdata/happy/evidence-occurrences.json) covers the new path.core.PropertyFilePathremains induplicatePropertiesin the SPDX marshaler: when an older SBOM is rescanned,reuseExistingBOM()passes the original components (which still contain the property) directly to the marshaler, so the filter is still needed to prevent a duplicateFilePathannotation in SPDX output.integration/testdata/fluentd-multiple-lockfiles-short.cdx.json.goldenis intentionally not changed: that test scans an old-style SBOM and outputs CycloneDX viareuseExistingBOM(), which passes the original components through unchanged, so the old property is (correctly) preserved in that output.Before
{ "purl": "pkg:conda/openssl@1.1.1q", "properties": [ { "name": "aquasecurity:trivy:FilePath", "value": "miniconda3/envs/testenv/conda-meta/openssl-1.1.1q-h7f8727e_0.json" }, { "name": "aquasecurity:trivy:PkgType", "value": "conda-pkg" } ] }After
{ "purl": "pkg:conda/openssl@1.1.1q", "properties": [ { "name": "aquasecurity:trivy:PkgType", "value": "conda-pkg" } ], "evidence": { "occurrences": [ { "location": "miniconda3/envs/testenv/conda-meta/openssl-1.1.1q-h7f8727e_0.json" } ] } }(Output of
trivy rootfs --format cyclonedxonintegration/testdata/fixtures/repo/conda.)Related issues
component.evidence.occurrences.locationfor filapaths and linenumber #9832Checklist
Made with Cursor