Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update npm nested (vulnerable) dependency?

Tags:

node.js

npm

Github has flagged a dependency in my app lock file as vulnerable.

To fix it I should updated that package to a newer version.

How do I do that if I don't have any control on the vulnerable package, because is nested in the dependencies tree?

Apologies if this is a very basic question but I don't seem to find anything useful regarding this.

like image 308
U r s u s Avatar asked Jan 15 '18 13:01

U r s u s


People also ask

How do I override nested npm dependency versions?

Remove the nested dependency under the 'requires' section in package-lock. json. Add the updated dependency under DevDependencies in package. json, so that modules that require it will still be able to access it.


1 Answers

You're correct - as the vulnerable package lies within one of your dependencies, like so:

Your Package -> Dependency -> Vulnerable package 

You will be unable to update the dependencies' dependency in a way that would survive a future npm install or yarn.

However, you could take the following approaches:

  • Bug the maintainer: Get them to update their dependencies and bump versions. This will fix the issue for you and your peers who are depending on this package.
  • Are there alternative packages? Maybe you can use a different package instead of the vulnerable one. This will involve some updates to your code, but might be the best approach in the long run, especially if the original maintainer is unresponsive.
  • Fix it yourself: Fork the repository and update the dependency in this copy. You can then refer to the package in your package.json.

See this answer for more information on installing directly from Github repos.

This approach will fix the problem short term, but it is not advised as you won't benefit from any bug fixes the maintainer makes, and besides, by the time you've done this the dependency might have been updated anyway!

like image 150
Tom Hallam Avatar answered Sep 23 '22 23:09

Tom Hallam