-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
NodeJS package-lock.json SBOM libraries list inconsistent #5532
Comments
Hello @OfirSandak
|
Hi @DmitriyLewen
|
I created image containing npm v8 and your FROM node:alpine3.15
COPY ./package-lock.json /app/package-lock.json
/app # npm ls --package-lock-only
[email protected] /app
`-- (empty)
I don't have |
Hey - Any news about this issue? |
Hello @sapirif |
I will give you an example - I used this package json - and generated lock file with this command: npm install --package-lock-only after running trivy twice with this command: trivy fs --format cyclonedx package-lock.json checking "components" part - got a diff in packages - Moreover we get some libraries that are not similar in those 2 files: In libs but not in lib2 In lib2 but not in lib Hope this will be enough details |
Thank you! I'm currently working on another task. When I have time, I’ll check the example and write to you. |
Hello everyone! Created aquasecurity/go-dep-parser#280 to fix this problem. |
Hi @DmitriyLewen, latest Trivy version released last week doesn't include this fix, is it possible to update Trivy to use go-dep-parser latest version? |
#5837 will be included in v0.49.0. |
The changes have been merged into |
Discussed in #5522
Originally posted by OfirSandak November 6, 2023
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
The text was updated successfully, but these errors were encountered: