I have a CI service that runs npm audit on every build and notifies if there are high-risk vulnerabilities. The strange thing is when CI reports high vulnerabilities when I run npm audit locally, it says found 0 vulnerabilities. It will find the issue in a few days...
For example, the CI reports about: CVE-2020-7774: The npm package y18n before versions 3.2.2, 4.0.1, and 5.0.5 is vulnerable to Prototype Pollution.
But on local dev env:
Both CI and local use Node 15.12.0 and npm 7.6.3.
Why is npm audit not finding the latest issues? Is there any way to force update it or something?
npm --verbose audit output:
Related
If I run npm upgrade or npm upgrade react-scripts I've always got the message like
added 84 packages, removed 249 packages, changed 428 packages, and audited 1245 packages in 57s
179 packages are looking for funding
run `npm fund` for details
6 moderate severity vulnerabilities
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
So I try npm audit fix --force and get a long report about dependencies and the text
66 vulnerabilities (15 low, 26 moderate, 24 high, 1 critical)
To address issues that do not require attention, run:
npm audit fix
To address all issues (including breaking changes), run:
npm audit fix --force
I follow these steps and run npm audit fix --force witch caused into errors:
npm ERR! code ERR_INVALID_ARG_TYPE
npm ERR! The "from" argument must be of type string. Received undefined
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\{user}\AppData\Local\npm-cache\_logs\2022-05-09T15_11_33_120Z-debug-0.log
If I try to run npm audit fix --force instead of npm audit fix I'm get the following:
nth-check <2.0.1
Severity: moderate
Inefficient Regular Expression Complexity in nth-check - https://github.com/advisories/GHSA-rp65-9cf3-cjxr
fix available via `npm audit fix --force`
Will install react-scripts#2.1.3, which is a breaking change
node_modules/svgo/node_modules/nth-check
css-select <=3.1.0
Depends on vulnerable versions of nth-check
node_modules/svgo/node_modules/css-select
svgo 1.0.0 - 1.3.2
Depends on vulnerable versions of css-select
node_modules/svgo
#svgr/plugin-svgo <=5.5.0
Depends on vulnerable versions of svgo
node_modules/#svgr/plugin-svgo
#svgr/webpack 4.0.0 - 5.5.0
Depends on vulnerable versions of #svgr/plugin-svgo
node_modules/#svgr/webpack
react-scripts >=2.1.4
Depends on vulnerable versions of #svgr/webpack
node_modules/react-scripts
6 moderate severity vulnerabilities
To address all issues (including breaking changes), run:
npm audit fix --force
And no, running npm audit fix --force once again does not help.
Can somebody help me?
As the new version 6.3.0 doesn't have the proper #svgo and #svgr we won't be able to access those modules. So, my suggestion is to go with the older version that is 5.2.0.
Instead of using the latest version use the older version
npm install react-router-dom#5.2.0
By running the above code in the promt we can access all the services of "react-router-dom".
Thank you :)
I was hung up on this problem too and got past it by updating my npm version to the latest, then for the specific package I was trying to update that caused the problem in the first place, I uninstalled and reinstalled it. I still get the 69 vulnerabilities message but the update did actually work. Good luck!
I'm trying to install react native on my Mac through the terminal using "sudo npm install -g expo-cli" but at the end of the installation errors appear.
115 packages are looking for funding
run `npm fund` for details
31 vulnerabilities (19 moderate, 12 high)
To address issues that do not require attention, run:
npm audit fix
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
Before trying to install react native I obviously installed nodeJS (16) in its latest version.
Anyone have an idea why the installation doesn't work?
when I do "npm audit fix" this is what it says:
npm ERR! code ENOLOCK
npm ERR! audit This command requires an existing lockfile.
npm ERR! audit Try creating one first with: npm i --package-lock-only
npm ERR! audit Original error: loadVirtual requires existing shrinkwrap file
Thank you in advance for your help.
Good news!
The first block you're referring to does not indicate installation failure. Your packages were installed correctly. The warnings are for nested security vulnerabilities which you can choose to address or ignore, depending on your app.
To prove that it was installed, run npm list -g in your terminal and see if expo-cli is in the list.
You can also check the packages installed correctly by creating a new react app using
npx create-react-app my-app
cd my-app
npm start
npm audit fix is intended to automatically upgrade / fix vulnerabilities in npm packages
There is something I don't understand with how npm audit fix works. From the docs:
npm audit fix runs a full-fledged npm install under the hood
So why when I run npm install and see audit vulnerabilities do I have to run npm audit fix manually to fix them?
npm install without any arguments will just install the dependencies in your package-lock.json (assuming it exists). npm audit fix will use the audit information to figure out what dependencies need to be upgraded and install them, as long as they don't conflict with your package.json.
I started a new npm repo (running in an official node docker container), installed the puppeteer package, and got a "high" severity vulnerability warning:
# node --version
v15.13.0
npm --version
7.8.0
# npm list
puppeteer#1.0.0 /home/node/puppeteer
`-- puppeteer#8.0.0
# npm audit
# npm audit report
puppeteer <1.13.0
Severity: high
Use-After-Free - https://npmjs.com/advisories/824
fix available via `npm audit fix`
1 high severity vulnerability
To address all issues, run:
npm audit fix
The puppeteer package version is obviously greater than 1.13.0, but it still warns about this "Use-After-Free" vulnerability. Needless to say, npm audit fix doesn't fix anything. What's going on?
I have this error whenever I install a package
found 14 vulnerabilities (1 low, 1 moderate, 12 high) run `npm audit fix` to fix them, or `npm audit` for details
So I have found out that some of my npm packages have a vulnerable version of a
dependency called tar. So all I need to do now is update this package to a higher version >= 4.4.2.
I manually changed the versions of all the tar dependencies in my package-lock.json and have tried to run the following commands
npm i
npm audit fix
npm audit fix --force
but the package-lock.json updates itself back to it's previous tar dependencies. I even ran npm cache clean --force and repeated the above command but the same result.
Is there a way I can specifically update every tar dependency within my node_modules from the command line?
npm audit fix changes package.json if needed by changing package versions to compatible ones, and package.json defines the possible versions that appear in package-lock.json.
So, you can't fix version-based vulnerabilities by rewriting package-lock.json because npm install rewrites package-lock.json anyway.
npm audit fix rewrites the versions in package.json to compatible versions that don't suffer from vulnerabilities. If running npm audit fix doesn't fix your version-based vulnerability issues, you have to refactor your code by using versions/libs that are not entirely compatible in the eyes of npm audit fix (in the real world, the changes are usually very minor). You can use the help of npm list to get the name of the dependency that requires an invalid version of tar, and change the version of this package.