#4293 Handle dependency with unspecified version to prevent NPE when scanning a lock file#4299
Conversation
|
Regarding the general approach: wouldn't you agree that supporting a version-less dependency (raising all vulnerabilities for any version of the dependency ) would be a way better approach than skipping the dependency when the package-lock contains no version? (which I would expect to be an improper package-lock by the way, as in my reading of NPMs package-lock documentation there should always be a version field). |
Hello! 👋
Yes, absolutely, as stated by https://docs.npmjs.com/cli/v8/configuring-npm/package-lock-json#dependencies. What made me make this choice was the OP package-lock.json inspection. My comment in #4293 is not detailed enough, I am sorry about that. Here are more details: So as stated in #4293, the NPE is raised by the following dependency mention: This is not the only place in the package-lock.json this dependency is mentioned. We do see it multiple times as it seems to be a transitive dependency of multiple For example, here it is mentioned in the
The cause of the issue is coming from I thought because it was mentioned as a peer dependency, the dependency itself must be declared somewhere else to be imported, so this very specific dependency object declared could be specified as a duplicate. After you comments and more thought, I'd say there is at least a flaw in my implementation. I should check at least the dependency is flagged as "peer" when ignoring because of no version. Your point looks also very valid. What if the only mention of a dependency is a wildcard as a peer? This looks kind of blurry as NPM seems to not have the same behavior given it's major version. I think it will end up being resolved by NPM as the latest version but some tests from my side would be needed. The point I would like to clarify with you is what do you think should we do in the OP case, which is we have a wildcard defined but we end up having a specific version number resolved in the file? Should we ignore the wild card to prevent raising too much false positive? I am putting this PR as a draft to prevent it being merged yet. Once you have the time to reply, I will work toward a solution that fits your specification (handling no version as wildcard + precision about the OP case). Thank you for your help! |
|
Checking for peer dependency would definitely be an improvement, however, not sure if it would be sufficient as npm appears to install the peer as needed when not installed (in versions 1.x, 2.x , removed in 3.x and re-added with improvements in 7.x) according to https://github.blog/2020-10-13-presenting-v7-0-0-of-the-npm-cli/ Not deep enough into the NPM ecosystem to be able to say for certain whether or not this would get reflected elsewhere in the package-lock.json or only take effect in the node_modules structure. |
Ok, so I will go with what you suggested in your first comment. It will be enough to fix the bug. I will update this PR and ask for a new review once I am done. Thank you. 👍 |
|
@nhumblot can you email me? jeremy.long @ gmail.com. |
|
Updated the change so Dependency Check does not ignore a dependency if it does not have a version. |
aikebah
left a comment
There was a problem hiding this comment.
Looks good to me; prefer to have @jeremylong also review before merging in
jeremylong
left a comment
There was a problem hiding this comment.
Looks good to me too - thanks!
Fixes Issue
Fix #4293
Description of Change
Prevent a
NullPointerExceptionduring lock file scan. This change handle the case where a version might not be specified for a dependency.Have test cases been added to cover the new functionality?
yes, one unit test has been modified to reproduce the NPE.
With the proposed changes, the package-json.zip file provided by the OP is analyzed without any issue and output an html report.
NB : I contributed for over a year to this project. I'll gladly take more responsibility in it if the maintainers wish to by inviting me to join as a collaborator. I think I may be able to assist the maintainers in the issue triage and management. 🙂