How to fix npm vulnerabilities manually?

node.jsNpmNpm Audit

node.js Problem Overview


When I run npm install it says found 33 vulnerabilities (2 low, 31 moderate) run `npm audit fix` to fix them, or `npm audit` for details.

However, npm audit fix outputs up to date in 11s fixed 0 of 33 vulnerabilities in 24653 scanned packages 33 vulnerabilities required manual review and could not be updated

Does that review mean it is not supposed to be fixed by user?

When I run npm audit it gives me list of tables, similar to this:

┌───────────────┬──────────────────────────────────────────────────────────────┐
│ LowPrototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Packagelodash                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=4.17.5                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency ofbrowser-sync [dev]                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Pathbrowser-sync > easy-extender > lodash                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More infohttps://nodesecurity.io/advisories/577                       │
└───────────────┴──────────────────────────────────────────────────────────────┘

In this example remediation section of linked page says Update to version 4.17.5 or later.. However, in /node_modules/browser-sync/package.json there are lines:

"devDependencies": {
    "lodash-cli": "4.17.5",
}

and no more lodash dependencies. So it should already be v4.17.5. I also checked /node_modules/lodash/lodash.json which has var VERSION = '4.17.10'; line. In /node_modules/lodash/package.json there are these lines:

  "_from": "lodash@^4.17.4",
  "_id": "[email protected]",

I believe that version shown in "_id", not in "_from", so versions are correct but vulnerability still appear in audit list.

I'm still new in node.js and those messages confuses me a lot. Is there any way to fix it manually or get rid of those messages, I can't do anything with?

node.js Solutions


Solution 1 - node.js

lodash-cli in devDependencies doesn't affect how browser-sync works in your project, devDependencies are ignored when a package is installed as a dependency.

What audit report says is that it's easy-extender that has lodash dependency:

browser-sync > easy-extender > lodash        

It depends on Lodash 3, while the problem was fixed in Lodash 4. The problem could be fixed by forking easy-extender, updating it and installing it instead of the package from NPM public registry. But there is no real problem with this dependency.

audit report importance should be evaluated manually. Even if nested dependency has security risk, this doesn't mean that a feature that introduces this risk was used. This also doesn't mean that even if it's used, it introduces real risk due to how it's used.

browser-sync is development tool that isn't used in production, there are not so many scenarios where its vulnerabilities could be exploited. And Prototype Pollution isn't a vulnerability at all, just a notice that a package doesn't follow good practices, it can be ignored.

Generally, this is the way to fix reported vulnerabilities:

  • Do a sanity check
  • In case it's a real problem, check the repository of vulnerable package for existing issues and PRs
  • In case there's none, submit an issue
  • Fork a repository or use use existing PR as git dependency until it's fixed in NPM release
  • In case of nested dependencies, do this at several levels of nesting

Most times it's expected that you won't advance beyond a sanity check, and the only problem is that a "vulnerability" clutters audit report and conceals real vulnerabilities.

patch-package can help to patch nested dependencies in-place but this won't affect the report.

It's possible to force specific dependency version in nested dependency in Yarn 1 and 2 with resolutions field, this will affect audit report. It may be possible to do this natively in NPM in future. Currently the alternative in NPM is third-party npm-force-resolutions utility that gives less control, currently it forces a resolution for all dependencies, not a specific one.

Notice that by forcing a dependency to use nested dependencies it wasn't designed to work with, it can become broken at any moment. This especially applies to npm-force-resolutions, which is a blunt tool and can affect many nested dependencies at once.

Solution 2 - node.js

If you are absolutely certain you'd like to skip the audit, you can do so by appending --no-audit

 npm install --no-audit

Solution 3 - node.js

'npm audit fix' will increment the version of dependency in package.json which might lead to breaking of code. So better way is to open package-lock.json and updated the dependency/subdependency versions to required version. Maintain the package-lock.json in repository.

Sometimes vulnerabilities are from dev packages, In that case ignore those vulnerabilities as those are not getting picked up in the production.

Solution 4 - node.js

use this

> npm audit fix --force --production

may be solve your problem

Solution 5 - node.js

You can you use force also like npm audit fix --force.

Solution 6 - node.js

I tried this and it worked for me, run the following commands:

> npm audit fix    
> npm set audit false

Solution 7 - node.js

The most of the problem occurred in my system was due to npm package. I tried,

npm un npm

You don't have to install again.

Just run program again. It worked for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJakupovView Question on Stackoverflow
Solution 1 - node.jsEstus FlaskView Answer on Stackoverflow
Solution 2 - node.jsTjad ClarkView Answer on Stackoverflow
Solution 3 - node.jsnikView Answer on Stackoverflow
Solution 4 - node.jscode chanView Answer on Stackoverflow
Solution 5 - node.js40SherrinView Answer on Stackoverflow
Solution 6 - node.jsAnyaView Answer on Stackoverflow
Solution 7 - node.jsGaurav RanaView Answer on Stackoverflow