-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Description
When scanning SBOM files with Trivy, many OS packages are missing from the output. This issue occurs when both in-graph OS packages (packages directly connected to the OS component in the dependency graph) and out-of-graph OS packages (orphaned packages not connected to the OS component) are present in the SBOM. Currently, only in-graph packages are included in the final output, while out-of-graph packages are excluded.
This is a general issue that affects all operating systems and SBOM formats.
Environment
- Trivy version: Latest main branch
- SBOM formats: CycloneDX, SPDX (potentially affects both)
- Test case: Amazon Linux 2023 (but affects all OS types)
Reproduction Steps
- Use the SBOM file from the discussion
- Run:
trivy sbom --list-all-pkgs --format json 9006.json
- Count packages:
jq '.Results[0].Packages | length'
Expected Behavior
Based on the original SBOM components:
jq '[.components[] | select(.type == "library")] | length' 9006.json
# Returns: 194
Both in-graph and out-of-graph OS packages should be included in the final output.
Actual Behavior
Current Trivy output:
./trivy sbom --list-all-pkgs --format json 9006.json | jq '.Results[0].Packages | length'
# Returns: 27
Only in-graph OS packages are included, while out-of-graph packages are excluded.
Root Cause
The issue occurs in the addOrphanPkgs
function in pkg/sbom/io/decode.go
. When both in-graph and out-of-graph OS packages exist:
- In-graph packages are processed first and added to a PackageInfo entry
- Out-of-graph packages are processed separately and put in a new PackageInfo entry instead of being merged with existing ones
- Only the first PackageInfo entry is retained in the final output
Impact
- Missing OS packages means vulnerability scanning may miss security issues in those packages
- Affects all OS types (Alpine, Debian, Ubuntu, RHEL, etc.) when scanning SBOM files
- Potentially affects both CycloneDX and SPDX formats
- Reduces accuracy of security scanning results
Related Discussion
This issue is based on the discussion: #9006
Metadata
Metadata
Assignees
Labels
Type
Projects
Status