-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(cyclonedx): preserve SBOM structure when scanning SBOM files with vulnerability updates #9439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
knqyf263
merged 8 commits into
aquasecurity:main
from
knqyf263:fix/sbom-reuse-bom-structure
Sep 20, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c7c9bae
fix(sbom): reuse existing BOM structure when available
knqyf263 171a130
fix(sbom): preserve external property names in CycloneDX format
knqyf263 f07c26c
test: update SPDX golden files after Property struct changes
knqyf263 d309c4f
fix(sbom): enable BOM-Ref auto-generation for CycloneDX formats
knqyf263 b62ab48
feat: add warning about filter flags for sbom-to-sbom-scan
DmitriyLewen 7a59f28
refactor: move and improve package filtering validation
knqyf263 9a39f27
Merge remote-tracking branch 'upstream/main' into fix/sbom-reuse-bom-…
knqyf263 360e677
fix: lint issues
knqyf263 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The scanned file ( |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| "$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json", | ||
| "bomFormat": "CycloneDX", | ||
| "specVersion": "1.6", | ||
| "serialNumber": "urn:uuid:3ff14136-e09f-4df9-80ea-000000000010", | ||
| "serialNumber": "urn:uuid:3ff14136-e09f-4df9-80ea-000000000006", | ||
| "version": 1, | ||
| "metadata": { | ||
| "timestamp": "2021-08-25T12:20:30+00:00", | ||
|
|
@@ -91,14 +91,6 @@ | |
| "name": "aquasecurity:trivy:LayerDigest", | ||
| "value": "sha256:000eee12ec04cc914bf96e8f5dee7767510c2aca3816af6078bd9fbe3150920c" | ||
| }, | ||
| { | ||
| "name": "aquasecurity:trivy:PkgID", | ||
| "value": "[email protected]" | ||
| }, | ||
| { | ||
| "name": "aquasecurity:trivy:PkgType", | ||
| "value": "debian" | ||
| }, | ||
| { | ||
| "name": "aquasecurity:trivy:SrcName", | ||
| "value": "bash" | ||
|
|
@@ -124,14 +116,6 @@ | |
| "name": "aquasecurity:trivy:LayerDigest", | ||
| "value": "sha256:000eee12ec04cc914bf96e8f5dee7767510c2aca3816af6078bd9fbe3150920c" | ||
| }, | ||
| { | ||
| "name": "aquasecurity:trivy:PkgID", | ||
| "value": "[email protected]" | ||
| }, | ||
| { | ||
| "name": "aquasecurity:trivy:PkgType", | ||
| "value": "debian" | ||
| }, | ||
| { | ||
| "name": "aquasecurity:trivy:SrcName", | ||
| "value": "libidn2" | ||
|
|
@@ -169,11 +153,7 @@ | |
| "value": "sha256:a8877cad19f14a7044524a145ce33170085441a7922458017db1631dcd5f7602" | ||
| }, | ||
| { | ||
| "name": "aquasecurity:trivy:PkgID", | ||
| "value": "[email protected]" | ||
| }, | ||
| { | ||
| "name": "aquasecurity:trivy:PkgType", | ||
| "name": "aquasecurity:trivy:Type", | ||
| "value": "gemspec" | ||
| } | ||
| ] | ||
|
|
@@ -193,18 +173,6 @@ | |
| "353f2470-9c8b-4647-9d0d-96d893838dc8", | ||
| "pkg:gem/[email protected]?file_path=var%2Flib%2Fgems%2F2.5.0%2Fspecifications%2Factivesupport-6.0.2.1.gemspec" | ||
| ] | ||
| }, | ||
| { | ||
| "ref": "pkg:deb/debian/[email protected]?distro=debian-10.2", | ||
| "dependsOn": [] | ||
| }, | ||
| { | ||
| "ref": "pkg:deb/debian/[email protected]?distro=debian-10.2", | ||
| "dependsOn": [] | ||
| }, | ||
| { | ||
| "ref": "pkg:gem/[email protected]?file_path=var%2Flib%2Fgems%2F2.5.0%2Fspecifications%2Factivesupport-6.0.2.1.gemspec", | ||
| "dependsOn": [] | ||
| } | ||
| ], | ||
| "vulnerabilities": [ | ||
|
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -367,6 +367,89 @@ func TestArtifact_Inspect(t *testing.T) { | |
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "components with missing BOM-REF", | ||
| filePath: filepath.Join("testdata", "bom-missing-refs.json"), | ||
| wantBlobs: []cachetest.WantBlob{ | ||
| { | ||
| ID: "sha256:512b9e999c9d7b4880c63ce55c2c74ea5c22b05cdbcb486097a16ec692c746a0", | ||
| BlobInfo: types.BlobInfo{ | ||
| SchemaVersion: types.BlobJSONSchemaVersion, | ||
| OS: types.OS{ | ||
| Family: "alpine", | ||
| Name: "3.16.0", | ||
| }, | ||
| PackageInfos: []types.PackageInfo{ | ||
| { | ||
| Packages: types.Packages{ | ||
| { | ||
| ID: "[email protected]", | ||
| Name: "musl", | ||
| Version: "1.2.3-r0", | ||
| SrcName: "musl", | ||
| SrcVersion: "1.2.3-r0", | ||
| Licenses: []string{"MIT"}, | ||
| Layer: types.Layer{ | ||
| DiffID: "sha256:dd565ff850e7003356e2b252758f9bdc1ff2803f61e995e24c7844f6297f8fc3", | ||
| }, | ||
| Identifier: types.PkgIdentifier{ | ||
| PURL: &packageurl.PackageURL{ | ||
| Type: packageurl.TypeApk, | ||
| Namespace: "alpine", | ||
| Name: "musl", | ||
| Version: "1.2.3-r0", | ||
| Qualifiers: packageurl.Qualifiers{ | ||
| { | ||
| Key: "distro", | ||
| Value: "3.16.0", | ||
| }, | ||
| }, | ||
| }, | ||
| // BOM-Ref should be auto-generated from PURL | ||
| BOMRef: "pkg:apk/alpine/[email protected]?distro=3.16.0", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| Applications: []types.Application{ | ||
| { | ||
| Type: "composer", | ||
| FilePath: "", | ||
| Packages: types.Packages{ | ||
| { | ||
| ID: "pear/[email protected]", | ||
| Name: "pear/log", | ||
| Version: "1.13.1", | ||
| Layer: types.Layer{ | ||
| DiffID: "sha256:3c79e832b1b4891a1cb4a326ef8524e0bd14a2537150ac0e203a5677176c1ca1", | ||
| }, | ||
| Identifier: types.PkgIdentifier{ | ||
| PURL: &packageurl.PackageURL{ | ||
| Type: packageurl.TypeComposer, | ||
| Namespace: "pear", | ||
| Name: "log", | ||
| Version: "1.13.1", | ||
| }, | ||
| // BOM-Ref should be auto-generated from PURL | ||
| BOMRef: "pkg:composer/pear/[email protected]", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| want: artifact.Reference{ | ||
| Name: filepath.Join("testdata", "bom-missing-refs.json"), | ||
| Type: types.TypeCycloneDX, | ||
| ID: "sha256:512b9e999c9d7b4880c63ce55c2c74ea5c22b05cdbcb486097a16ec692c746a0", | ||
| BlobIDs: []string{ | ||
| "sha256:512b9e999c9d7b4880c63ce55c2c74ea5c22b05cdbcb486097a16ec692c746a0", | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "sad path with no such directory", | ||
| filePath: filepath.Join("testdata", "unknown.json"), | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We calc the SPDX-ID as a hash of
core.component:trivy/pkg/sbom/spdx/marshal.go
Lines 319 to 320 in d2d0ec2
So after adding
core.Property.Externalfield, the hash was changed.