[Bug] yarn npm audit doesn't report all vulnerabilities
See original GitHub issue- Iβd be willing to implement a fix
Describe the bug
yarn npm audit -R
(yarn2) doesnβt report some vulnerabilities which are detected with npm audit
and yarn audit
(yarn1)
In my case when a dependencies is present with 2 different version, only the newer one seems to be taken into consideration, which hide the vulnerabilities of the older one
To Reproduce
Reproduction
await packageJsonAndInstall({
dependencies: {
[`react`]: `16.14.0`,
},
devDependencies: {
[`@storybook/react`]: `6.1.18`,
[`react-scripts`]: `4.0.3`,
},
});
const output = await yarn(`npm`, `audit`, `-R`);
expect(output).not.toContain(`No audit suggestions`);
package.json
{
"name": "foo",
"version": "1.0.0",
"private": true,
"dependencies": {
"react": "16.14.0"
},
"devDependencies": {
"@storybook/react": "6.1.18",
"react-scripts": "4.0.3"
}
}
With yarn2, no vulnerability is found
yarn install
[...]
yarn npm audit -R
β€ YN0001: No audit suggestions
With npm, a vulnerability related to immer
is reported
npm install --force
[... report 4 vulnerabilities]
npm audit
# npm audit report
immer <8.0.1
Severity: high
Prototype Pollution - https://npmjs.com/advisories/1603
fix available via `npm audit fix --force`
Will install @storybook/react@4.0.2, which is a breaking change
node_modules/immer
react-dev-utils 6.0.6-next.9b4009d7 - 11.0.2
Depends on vulnerable versions of immer
node_modules/react-dev-utils
@storybook/core 4.0.3 - 6.2.0-alpha.2
Depends on vulnerable versions of react-dev-utils
node_modules/@storybook/core
@storybook/react 4.0.3 - 6.2.0-alpha.2
Depends on vulnerable versions of react-dev-utils
node_modules/@storybook/react
4 high severity vulnerabilities
To address issues that do not require attention, run:
npm audit fix
To address all issues (including breaking changes), run:
npm audit fix --force
With yarn1, the same vulnerability to immer
is reported
yarn install
[...]
β― yarn audit
yarn audit v1.22.10
βββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β high β Prototype Pollution β
βββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Package β immer β
βββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Patched in β >=8.0.1 β
βββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Dependency of β @storybook/react β
βββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Path β @storybook/react > @storybook/core > react-dev-utils > immer β
βββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β More info β https://www.npmjs.com/advisories/1603 β
βββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β high β Prototype Pollution β
βββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Package β immer β
βββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Patched in β >=8.0.1 β
βββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Dependency of β @storybook/react β
βββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Path β @storybook/react > react-dev-utils > immer β
βββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β More info β https://www.npmjs.com/advisories/1603 β
βββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
2 vulnerabilities found - Packages audited: 2087
Severity: 2 High
Done in 1.69s.
Even with yarn2, immer
dependency 1.10.0 is present in the dependency tree and should have been reported. Note that in that case immer
is present in two version, 1.10.0 which is vulnerable and 8.0.1 which is not vulnerable/
yarn why -R immer
ββ foo@workspace:.
ββ @storybook/react@npm:6.1.18 [6847a] (via npm:6.1.18 [6847a])
β ββ react-dev-utils@npm:10.2.1 (via npm:^10.0.0)
β β ββ immer@npm:1.10.0 (via npm:1.10.0)
β ββ @storybook/core@npm:6.1.18 [1e78a] (via npm:6.1.18 [1e78a])
β ββ react-dev-utils@npm:10.2.1 (via npm:^10.0.0)
ββ react-scripts@npm:4.0.3 [6847a] (via npm:4.0.3 [6847a])
ββ react-dev-utils@npm:11.0.3 (via npm:^11.0.3)
ββ immer@npm:8.0.1 (via npm:8.0.1)
Removing react-scripts
dependency from package.json
and now the immer
vulnerability is reported with yarn2 too (still as with npm and yarn1):
yarn npm audit -R
ββ immer: 1.10.0
ββ Issue: Prototype Pollution
ββ URL: https://npmjs.com/advisories/1603
ββ Severity: high
ββ Vulnerable Versions: <8.0.1
ββ Patched Versions: >=8.0.1
ββ Via: @storybook/react
ββ Recommendation: Upgrade to version 8.0.1 or later
So it seems that when a dependency is present with 2 different versions, only the newer one is used for the audit command which is a flaw in the vulnerability detection.
yarn npm audit feature has been added in https://github.com/yarnpkg/berry/pull/1892
Environment if relevant (please complete the following information):
- OS: Windows 10
- Node version: 15.9.0
- Yarn version: 2.4.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:12
- Comments:6 (1 by maintainers)
Same here:
Adding the
--recursive
flag actually results in an HTTP error:(the suggested
yarn install
doesnβt help)Yarn reports no vulnerabilities (or rather, βYN0001: No audit suggestionsβ) on our whole tree of dependencies, no matter if we pass it various options, while NPM reports 329 vulnerabilities (3 low, 324 moderate, 2 high). Itβs enough to prevent us from migrating from npm for the time being.
Looking forward to
yarn npm audit
working at least as well asnpm audit
and we can enjoy all the other Yarn goodies.