fix(vex): avoid panic on CSAF relationships without a sub-component - #11067
Open
ashvinctrl wants to merge 1 commit into
Open
fix(vex): avoid panic on CSAF relationships without a sub-component#11067ashvinctrl wants to merge 1 commit into
ashvinctrl wants to merge 1 commit into
Conversation
reachRoot evaluates the leaf component on its own before walking up to the root, passing a nil sub-component. matchRelationship dereferenced it unconditionally, so a CSAF document whose relationship relates to a component that is itself vulnerable crashed the scan. A relationship describes a sub-component within a product, so it cannot match when no sub-component is given.
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
Scanning with a CSAF VEX document crashes with a nil pointer panic when the document declares a relationship and the vulnerability is detected on the product that relationship relates to.
reachRootevaluates the leaf component on its own before walking up to the root, and passes a nil sub-component:matchRelationshipdereferenced that argument without a check:So as soon as a relationship's
relates_to_product_referenceresolves to a PURL that matches a vulnerable component, the scan segfaults.OpenVEX.Matchesalready guards the same argument; CSAF did not.A relationship describes a sub-component within a product, so it cannot match when no sub-component is given. This returns early in that case, which leaves the existing matching behaviour untouched.
The panic aborts the whole scan with exit code 2, and crashes programs that embed Trivy as a library.
There is no associated issue. The fix is small and self-contained, so per the contributing guide I'm including the justification here instead.
Reproduction
A CycloneDX SBOM with
github.com/gogo/protobuf@v1.3.1(CVE-2021-3121) and a child component, plus a CSAF document that puts the child inside protobuf:Before
After
The scan completes, and the vulnerability on protobuf is still reported, since the statement covers the child as a component of protobuf and not protobuf itself:
Relationship filtering itself is unchanged. With the same SBOM shape inverted, so that protobuf is the sub-component of a parent module, the statement still suppresses the finding:
Related issues
N/A
Checklist