-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(nodejs): fix npmjs parser.pkgNameFromPath() panic issue #9688
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
Conversation
|
Hello @derekhjray Can you share example how we can reproduce this issue? |
|
@DmitriyLewen Nodejs parser.parseV2->parser.pkgNameFromPath() processing a nodejs path with suffix "node_modules", such as "xxxx/node_modules", but has no trailing slash or sub-package name, the func access string slice with 'path[index + len(node_modules) + 1:]' will panic, and I have no idea why nodejs parser got a javascript package path with no trailing slash and package name |
|
@DmitriyLewen |
Trivy doesn't check npm lock files in
It looks like this is invalid lock file. Can you share this package-lock.json file? |
|
Sorry, I can not get the package-lock.json file myself, I just fix it from panic log, and it's just an insurance and compatile fixture for invalid nodejs lock file for both image and filesystem scanning. If it's not an issue for your consideration, I can close this pr |
|
I just wanted to understand how this is possible. |
| if index+len(nodeModulesDir) == len(pkgPath) { | ||
| return "" | ||
| } | ||
|
|
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.
Is it possible to add a warning here since the package-lock.json file is invalid in this case?
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.
Yes, you could add warning message to warn the lock file is malformed
|
@DmitriyLewen |
Co-authored-by: DmitriyLewen <[email protected]>
DmitriyLewen
left a comment
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.
@derekhjray Thanks for your work!
I refactored code a bit.
The invalid lock file triggered this panic is from another team, And they refuse to provide the original file, and I cannot figure out why this happened either.
If you manage to reproduce this case or get a file from this team, I would be very grateful if you sent it.
OK, I will share the file if reproduce this panic and got the original file |
…rity#9688) Co-authored-by: DmitriyLewen <[email protected]> Co-authored-by: DmitriyLewen <[email protected]>
Description
nodejs parser will panic if parser.pkgNameFromPath invoked with parameter 'xxxx/node_modules' which has no trailing slash or submodule
Checklist