-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(sbom): add BOMID field to match packages and decoded BOM components
#9597
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
base: main
Are you sure you want to change the base?
feat(sbom): add BOMID field to match packages and decoded BOM components
#9597
Conversation
- fill BOMID only when decode SBOM - use BOMID to match component and vuln
|
|
||
| components := lo.MapEntries(bom.Components(), func(_ uuid.UUID, component *core.Component) (string, *core.Component) { | ||
| return component.PkgIdentifier.UID, component | ||
| return cmp.Or(component.ID().String(), component.PkgIdentifier.UID), component |
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.
The main problem in #9593 is that the decoded BOM component (from a reused BOM) doesn’t have a UID field.
I tried to fix this in this package, but we run into the following scenarios:
| mode | component fields | vulnerability fields |
|---|---|---|
| fs mode | UID + PURL | UID + PURL |
| scan CycloneDX file | UID + bom-ref + PURL | UID + bom-ref + PURL |
| scan SPDX file | PURL | UID + PURL |
There are two problems:
- We can’t define a consistent matching order, so in some cases we have to check the components map up to three times.
- We have to rely on PURL for SPDX, which isn’t ideal because multiple packages can share the same PURL.
I thought about adding a new field for SPDX-ID, but in that case there would still be a question of how to efficiently check the components map.
So I chose this approach instead.
BOMID is used only for decoded components, which allows us to reliably match components with vulnerabilities/packages.
@knqyf263 let me know what you think. If this looks good, I’ll go ahead and update the tests, comments, logs, etc.
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 found another approach:
we can calculate the UID after decoding the package and then update the component with this UID.
Please take a look at this branch: https://github.com/DmitriyLewen/trivy/tree/fix/add-uid-for-decoded-bom-components
Also, we can use the UID to match components with vulnerabilities.
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 can calculate the UID after decoding the package and then update the component with this UID.
After reading the content of the issue (and before reading this PR), I was just about to propose exactly this change. I think it’s generally good, but wouldn’t it be better to insert the UID inside decodePackage?
pkg.Identifier.UID = dependency.UID(pkg.FilePath, *pkg)
return pkg, nil
// Overwrite component with UID for package
c.PkgIdentifier.UID = pkg.Identifier.UID
m.bom.AddComponent(c)
Since the returned package will be stored in m.pkgs, it might be better to save the UID before that point.
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.
However, I planned to add BOMID or something similar in the future. It may be a good idea to do that now.
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'll make a quick PoC—just a second.
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 was thinking about that too.
IIUC, we'll need to revert some changes:
- aff03eb#diff-bda89d30f6e4b3fac0df2f83407739dc83f36828c830d5860fa5b9cf61083260
- aff03eb#diff-bda89d30f6e4b3fac0df2f83407739dc83f36828c830d5860fa5b9cf61083260L288-L291 (i am not sure about this)
This means we’ll need to update the logic for the root component in two places (for the reusable BOM and for the VEX case).
It shouldn’t be difficult, but it’s something we need to keep in mind.
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.
File selection in GitHub commit URLs doesn’t navigate properly (is it just my browser?), so I couldn’t see which file you were referring to. Since we only need the tree in VEX, I thought it would be fine to regenerate it, but is there any issue with that?
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.
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 tried to write a test to demonstrate my thoughts, but it looks like this is a very hard-to-reproduce case and probably doesn’t occur in normal usage.
So for now, I’ll apply your suggested changes and create another PR.
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.
created #9604
BOMID field to match packages and decoded componentsBOMID field to match packages and decoded BOM components


Description
This PR fixes an issue with matching vulnerabilities to packages and components when working with SBOM (Software Bill of Materials) files. The main problem was that vulnerabilities weren't being properly matched to their corresponding
components during SBOM processing, particularly in VEX (Vulnerability Exploitability eXchange) filtering scenarios.
The solution introduces a new BOMID field that provides a reliable UUID-based identifier for matching components between decoded SBOM data and vulnerability information. This ensures accurate component-to-vulnerability associations in
both SBOM scanning mode and regular scanning modes.
Made Changes
These changes ensure that vulnerabilities are correctly filtered and associated with their corresponding components regardless of whether they come from SBOM files or regular package scans.
Related issues
Related PRs
Checklist