NodeJS package-lock.json SBOM libraries list inconsistent #5522
Closed
OfirSandak
started this conversation in
Bugs
Replies: 1 comment
-
Hello @OfirSandak I created #5532 for this issue. Regards, Dmitriy |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
I want to report an issue related to Trivy filesystem scan when generating CycloneDX SBOM from package-lock.json. The problem arises when running the scan multiple times, as it returns different libraries with each run.
Upon investigation, the root cause of this inconsistency appears to be the presence of two instances of a library in package-lock.json, one with "dev": true and another without. The issue lies within the go-dep-parser package. In the Node.js npm parser, the dependencies map in package-lock.json is unmarshaled into a slice. During this process, any duplicate libraries are removed. However, the first instance of a library is kept after deduplication. Since the map unmarshaling is not in order, the first instance of the library can be either with or without "dev": true.
In the Trivy local scan, the dev libraries are removed at the excludeDevDeps function in pkg/scanner/local/scan.go. Consequently, this leads to different results for the same package-lock.json file.
Desired Behavior
Runs should be consistent, ensuring that libraries with an instance of
"dev": false
always supersede any instance with"dev": true
.Actual Behavior
The inconsistency arises because each run produces different results, depending on which library instance is first unmarshaled from the package-lock.json file
Reproduction Steps
Target
Filesystem
Scanner
None
Output Format
CycloneDX
Mode
Standalone
Debug Output
Operating System
macOS 13.6
Version
Checklist
trivy image --reset
Beta Was this translation helpful? Give feedback.
All reactions