Extract CPE/PURL from all CycloneDX objects that carry them - #318
Merged
Conversation
GetCPEDetail already reaches past Syft's decoded packages into the raw SBOM component list to pick up CPEs on components Syft doesn't surface (components of type "file" being the common case). GetPURLDetail didn't do the equivalent for PURLs: it iterated only sbm.Artifacts.Packages and used inputRefs solely to backfill SbomRef metadata onto packages Syft had already found. A component carrying only a purl — no matching Syft package — was silently dropped, so its vulnerabilities never got looked up. Rewrites GetPURLDetail to mirror GetCPEDetail: dedupe by PURL string, apply the same pkg:github filter, then append any PURL from inputRefs that wasn't already accounted for. Extends TestGetPURLDetail to assert PURLs from inputRefs come through, duplicates collapse, empty PURLs and pkg:github refs get filtered. Verified the extended assertion fails against the previous code.
The CycloneDX metadata.component object describes what the SBOM is about — often the top-level scanned artifact (an OS image, a firmware blob, an application). It's the natural place to attach a purl or cpe identifying the product as a whole, but Syft does not surface it as a package, and the raw-JSON pass only walked the top-level components[] array. So a purl/cpe declared there was silently ignored. Extracts a small appendRef helper from the existing components walk and uses it for metadata.component as well. Adds a minimal fixture (testdata/cyclonedx-metadata-component.json) and TestLoadSBOM_MetadataComponent covering the case. Verified the assertion fails against the previous code.
tcampbPPU
approved these changes
Jul 23, 2026
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.
Summary
bill.GetPURLDetailto mirrorbill.GetCPEDetail: after iterating the packages Syft surfaces, walk the raw-JSONinputRefsand append any PURL that Syft did not already account for. Dedupe by PURL string; apply the samepkg:githubfilter. PreviouslyinputRefswas used only to backfillSbomRefmetadata onto packages Syft had found, so a CycloneDX component carrying only apurl(e.g. atype: "file"entry) was silently dropped.bill.LoadSBOMto also readmetadata.component. That object describes what the SBOM is about — often the top-level scanned artifact (an OS image, a firmware blob, an application) — and is the natural place to attach apurlorcpeidentifying the product as a whole. Syft does not surface it as a package, and the raw walk only looked at the top-levelcomponents[]array, so any identifier attached there was ignored.TestGetPURLDetailwith the same shapeTestGetCPEDetailalready uses (dedupe, empty, filter). AddTestLoadSBOM_MetadataComponentand a minimal fixture. Each new assertion was verified to fail against the pre-change code.Why
Offline mode is meant to emulate the API for air-gapped users, but a CycloneDX SBOM has several standard places where a
purlorcpecan legitimately appear beyond the top-levelcomponents[]. When we miss any of them we silently under-scan — the customer sees fewer vulnerabilities than online mode would find. Two of those gaps came up in prior customer reports (both fixed for CPE, one still open for PURL, and neither coveredmetadata.component). This PR closes both concrete gaps and adds regression coverage so the same class of bug can't come back.Test plan
go test ./pkg/bill/...passesgo build ./...cleanmetadata.componentdeclares acpeorpurlnow reports vulnerabilities against it instead of ignoring ittype: "file"(or otherwise non-package) component now surfaces that PURL's vulnerabilities