-
Notifications
You must be signed in to change notification settings - Fork 186
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
Fix crash when parsing valid CycloneDX formats missing optional metadata fields #896
Closed
kurt-r2c
wants to merge
1
commit into
guacsec:main
from
kurt-r2c:kb/component-metadata-spec-adherence
Closed
Changes from all commits
Commits
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
95 changes: 95 additions & 0 deletions
95
internal/testing/testdata/exampledata/cyclonedx-bom-example.json
This file contains 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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
"$schema": "http://cyclonedx.org/schema/bom-1.4.schema.json", | ||
"bomFormat": "CycloneDX", | ||
"specVersion": "1.4", | ||
"serialNumber": "urn:uuid:588bb01b-577e-4e1b-a055-b51b8f5f2ed1", | ||
"version": 1, | ||
"metadata": { | ||
"timestamp": "2023-04-18T21:47:45.707189+00:00", | ||
"tools": [ | ||
{ | ||
"vendor": "CycloneDX", | ||
"name": "cyclonedx-bom", | ||
"version": "3.11.0" | ||
}, | ||
{ | ||
"vendor": "CycloneDX", | ||
"name": "cyclonedx-python-lib", | ||
"version": "3.1.5", | ||
"externalReferences": [ | ||
{ | ||
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/actions", | ||
"type": "build-system" | ||
}, | ||
{ | ||
"url": "https://pypi.org/project/cyclonedx-python-lib/", | ||
"type": "distribution" | ||
}, | ||
{ | ||
"url": "https://cyclonedx.github.io/cyclonedx-python-lib/", | ||
"type": "documentation" | ||
}, | ||
{ | ||
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/issues", | ||
"type": "issue-tracker" | ||
}, | ||
{ | ||
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/LICENSE", | ||
"type": "license" | ||
}, | ||
{ | ||
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/CHANGELOG.md", | ||
"type": "release-notes" | ||
}, | ||
{ | ||
"url": "https://github.com/CycloneDX/cyclonedx-python-lib", | ||
"type": "vcs" | ||
}, | ||
{ | ||
"url": "https://cyclonedx.org", | ||
"type": "website" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"components": [ | ||
{ | ||
"type": "library", | ||
"bom-ref": "13ca86b0-38a2-47aa-9a39-b2b042da8bc4", | ||
"name": "ruamel.yaml", | ||
"version": "0.17.21", | ||
"purl": "pkg:pypi/[email protected]", | ||
"externalReferences": [ | ||
{ | ||
"url": "https://pypi.org/project/ruamel.yaml/0.17.21", | ||
"comment": "Distribution available from pypi.org", | ||
"type": "distribution", | ||
"hashes": [ | ||
{ | ||
"alg": "SHA-256", | ||
"content": "742b35d3d665023981bd6d16b3d24248ce5df75fdb4e2924e93a05c1f8b61ca7" | ||
} | ||
] | ||
}, | ||
{ | ||
"url": "https://pypi.org/project/ruamel.yaml/0.17.21", | ||
"comment": "Distribution available from pypi.org", | ||
"type": "distribution", | ||
"hashes": [ | ||
{ | ||
"alg": "SHA-256", | ||
"content": "8b7ce697a2f212752a35c1ac414471dc16c424c9573be4926b56ff3f5d23b7af" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"dependencies": [ | ||
{ | ||
"ref": "13ca86b0-38a2-47aa-9a39-b2b042da8bc4", | ||
"dependsOn": [] | ||
} | ||
] | ||
} |
This file contains 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 |
---|---|---|
|
@@ -91,6 +91,9 @@ var ( | |
//go:embed exampledata/no-dependent-components-cyclonedx.json | ||
CycloneDXExampleNoDependentComponents []byte | ||
|
||
//go:embed exampledata/cyclonedx-bom-example.json | ||
CycloneDXExampleCycloneDXpyNoBOMRef []byte | ||
|
||
//go:embed exampledata/crev-review.json | ||
ITE6CREVExample []byte | ||
|
||
|
@@ -798,6 +801,30 @@ var ( | |
HasSBOM: CdxNpmHasSBOM, | ||
} | ||
|
||
cdxPyRuamelPackage, _ = asmhelpers.PurlToPkg("pkg:pypi/[email protected]") | ||
|
||
CdxPipenvDeps = []assembler.IsDependencyIngest{ | ||
{ | ||
Pkg: cdxPyRuamelPackage, | ||
}, | ||
} | ||
|
||
CdxPipenvHasSBOM = []assembler.HasSBOMIngest{ | ||
{ | ||
Pkg: cdxPyRuamelPackage, | ||
HasSBOM: &model.HasSBOMInputSpec{ | ||
Uri: "TestSource", | ||
Algorithm: "sha256", | ||
Digest: "35363f03c80f26a88db6f2400771bdcc6624bb7b61b96da8503be0f757605fde", | ||
DownloadLocation: "TestSource", | ||
}, | ||
}, | ||
} | ||
|
||
CdxPipenvIngestionPredicates = assembler.IngestPredicates{ | ||
//without a root node, the parser will return empty predicates. Not sure what the "correct" behavior here should be | ||
} | ||
|
||
quarkusParentPackage, _ = asmhelpers.PurlToPkg("pkg:maven/io.quarkus/quarkus-parent@999-SNAPSHOT?type=pom") | ||
|
||
quarkusParentPackageHasSBOM = []assembler.HasSBOMIngest{ | ||
|
This file contains 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 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
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.
Hello @kurt-r2c! Thanks for the PR! This is something that warrants further discussion/thought on how it should be handled in GUAC, as we could potentially not have a top-level component. I will keep you posted and we can update this PR as needed.
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.
I am wondering what the use case of having a CDX document without the top level component is for... if it is the case where it is interpretted as here's a list of all the components I use, then it should parse to a bunch of singletons, however, if it is not , then my thought would be to either use the generic
guac/cdx/<name>
or to just reject it. let's make sure we have this on the priority for triage.