feat: allow audit --fix to skip installing overrides based on allowList array in the manifest (#5592)

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Coby Sher
2022-11-07 19:33:58 -06:00
committed by GitHub
parent 6710d9dd90
commit 702e847c1c
7 changed files with 481 additions and 3 deletions

View File

@@ -0,0 +1,22 @@
---
"@pnpm/plugin-commands-audit": minor
"@pnpm/types": minor
"pnpm": minor
---
A new setting supported for ignoring vulnerabilities by their CVEs. The ignored CVEs may be listed in the `pnpm.auditConfig.ignoreCves` field of `package.json`. For instance:
```
{
"pnpm": {
"auditConfig": {
"ignoreCves": [
"CVE-2019-10742",
"CVE-2020-28168",
"CVE-2021-3749",
"CVE-2020-7598"
]
}
}
}
```

View File

@@ -9,6 +9,7 @@ import { Registries } from '@pnpm/types'
import { table } from '@zkochan/table'
import chalk from 'chalk'
import pick from 'ramda/src/pick'
import { difference } from 'ramda'
import renderHelp from 'render-help'
import { fix } from './fix'
@@ -126,6 +127,7 @@ export async function handler (
| 'optional'
| 'userConfig'
| 'rawConfig'
| 'rootProjectManifest'
>
) {
const lockfile = await readWantedLockfile(opts.lockfileDir ?? opts.dir, { ignoreIncompatible: true })
@@ -202,7 +204,12 @@ ${JSON.stringify(newOverrides, null, 2)}`,
let output = ''
const auditLevel = AUDIT_LEVEL_NUMBER[opts.auditLevel ?? 'low']
const advisories = Object.values(auditReport.advisories)
let advisories = Object.values(auditReport.advisories)
const ignoreCves = opts.rootProjectManifest?.pnpm?.auditConfig?.ignoreCves
if (ignoreCves) {
advisories = advisories.filter(({ cves }) => difference(cves, ignoreCves).length > 0)
}
advisories = advisories
.filter(({ severity }) => AUDIT_LEVEL_NUMBER[severity] >= auditLevel)
.sort((a1, a2) => AUDIT_LEVEL_NUMBER[a2.severity] - AUDIT_LEVEL_NUMBER[a1.severity])
for (const advisory of advisories) {

View File

@@ -1,10 +1,11 @@
import { AuditReport, AuditAdvisory } from '@pnpm/audit'
import { readProjectManifest } from '@pnpm/read-project-manifest'
import { difference } from 'ramda'
import fromPairs from 'ramda/src/fromPairs'
export async function fix (dir: string, auditReport: AuditReport) {
const { manifest, writeProjectManifest } = await readProjectManifest(dir)
const vulnOverrides = createOverrides(Object.values(auditReport.advisories))
const vulnOverrides = createOverrides(Object.values(auditReport.advisories), manifest.pnpm?.auditConfig?.ignoreCves)
if (Object.values(vulnOverrides).length === 0) return vulnOverrides
await writeProjectManifest({
...manifest,
@@ -19,7 +20,10 @@ export async function fix (dir: string, auditReport: AuditReport) {
return vulnOverrides
}
function createOverrides (advisories: AuditAdvisory[]) {
function createOverrides (advisories: AuditAdvisory[], ignoreCves?: string[]) {
if (ignoreCves) {
advisories = advisories.filter(({ cves }) => difference(cves, ignoreCves).length > 0)
}
return fromPairs(
advisories
.filter(({ vulnerable_versions, patched_versions }) => vulnerable_versions !== '>=0.0.0' && patched_versions !== '<0.0.0') // eslint-disable-line

View File

@@ -982,3 +982,371 @@ exports[`audit 1`] = `
46 vulnerabilities found
Severity: 4 low | 17 moderate | 21 high | 4 critical"
`;
exports[`audit: CVEs in ignoreCves do not show up 1`] = `
"┌─────────────────────┬───────────────────────────────────────────────────────┐
│ critical │ Improper Certificate Validation in xmlhttprequest-ssl │
├─────────────────────┼───────────────────────────────────────────────────────┤
│ Package │ xmlhttprequest-ssl │
├─────────────────────┼───────────────────────────────────────────────────────┤
│ Vulnerable versions │ <1.6.1 │
├─────────────────────┼───────────────────────────────────────────────────────┤
│ Patched versions │ >=1.6.1 │
├─────────────────────┼───────────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-72mh-269x-7mh5 │
└─────────────────────┴───────────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ critical │ Command injection in nodemailer │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ nodemailer │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <6.4.16 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=6.4.16 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-48ww-j4fc-435p │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ critical │ Insufficient Entropy in cryptiles │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ cryptiles │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <4.1.2 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=4.1.2 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-rq8g-5pc5-wrhr │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ critical │ Improper parsing of octal bytes in netmask │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ netmask │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <1.1.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=1.1.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-4c7m-wxvm-r7gc │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────┐
│ high │ Arbitrary File Creation/Overwrite on Windows via insufficient relative path sanitization │
├─────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────┤
│ Package │ tar │
├─────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <4.4.18 │
├─────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────┤
│ Patched versions │ >=4.4.18 │
├─────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-5955-9wpr-37jh │
└─────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ high │ Arbitrary File Creation/Overwrite via insufficient symlink protection due to directory cache poisoning using symbolic links │
├─────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Package │ tar │
├─────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <4.4.18 │
├─────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Patched versions │ >=4.4.18 │
├─────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-qq89-hq3f-393p │
└─────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ high │ Arbitrary File Creation/Overwrite via insufficient symlink protection due to directory cache poisoning using symbolic links │
├─────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Package │ tar │
├─────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <4.4.16 │
├─────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Patched versions │ >=4.4.16 │
├─────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-9r2w-394v-53qc │
└─────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ high │ Code Injection in pac-resolver │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ pac-resolver │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <5.0.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=5.0.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-9j49-mfvp-vmhm │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ high │ Resource exhaustion in socket.io-parser │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ socket.io-parser │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <3.3.2 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=3.3.2 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-xfhh-g9f5-x4m4 │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ high │ Arbitrary Code Injection │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ xmlhttprequest-ssl │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <1.6.2 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=1.6.2 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-h4j5-c7cj-74xg │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ high │ Arbitrary Code Execution in underscore │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ underscore │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ >=1.3.2 <1.12.1 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=1.12.1 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-cf4h-3jhx-xvhq │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ high │ Path traversal in url-parse │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ url-parse │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <1.5.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=1.5.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-9m6j-fcg5-2442 │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ high │ Remote Memory Exposure in bl │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ bl │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <1.2.3 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=1.2.3 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-pp7h-53gx-mx7r │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ high │ Validation Bypass in kind-of │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ kind-of │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ >=6.0.0 <6.0.3 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=6.0.3 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-6c8f-qphg-qjgp │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────────┐
│ high │ Exposure of sensitive information in follow-redirects │
├─────────────────────┼───────────────────────────────────────────────────────┤
│ Package │ follow-redirects │
├─────────────────────┼───────────────────────────────────────────────────────┤
│ Vulnerable versions │ <1.14.7 │
├─────────────────────┼───────────────────────────────────────────────────────┤
│ Patched versions │ >=1.14.7 │
├─────────────────────┼───────────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-74fj-2j2h-c42q │
└─────────────────────┴───────────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ high │ Regular expression denial of service │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ glob-parent │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <5.1.2 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=5.1.2 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-ww39-953v-wcq6 │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ high │ Command Injection in lodash │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ lodash │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <4.17.21 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=4.17.21 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-35jh-r3h4-6jhm │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ high │ Prototype Pollution in lodash │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ lodash │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <4.17.19 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=4.17.19 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-p6mc-m468-83gw │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ high │ Resource exhaustion in engine.io │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ engine.io │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <4.0.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=4.0.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-j4f2-536g-r55m │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ high │ Authorization bypass in url-parse │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ url-parse │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <1.5.6 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=1.5.6 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-rqff-837h-mm52 │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ moderate │ Prototype Pollution in node-jsonpointer │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ jsonpointer │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <5.0.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=5.0.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-282f-qqgm-c34q │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ moderate │ Open redirect in url-parse │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ url-parse │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <1.5.2 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=1.5.2 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-hh27-ffr2-f2jc │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────┐
│ moderate │ netmask npm package vulnerable to octal input data │
├─────────────────────┼────────────────────────────────────────────────────┤
│ Package │ netmask │
├─────────────────────┼────────────────────────────────────────────────────┤
│ Vulnerable versions │ <2.0.1 │
├─────────────────────┼────────────────────────────────────────────────────┤
│ Patched versions │ >=2.0.1 │
├─────────────────────┼────────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-pch5-whg9-qr2r │
└─────────────────────┴────────────────────────────────────────────────────┘
┌─────────────────────┬─────────────────────────────────────────────────────────────┐
│ moderate │ Insecure defaults due to CORS misconfiguration in socket.io │
├─────────────────────┼─────────────────────────────────────────────────────────────┤
│ Package │ socket.io │
├─────────────────────┼─────────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <2.4.0 │
├─────────────────────┼─────────────────────────────────────────────────────────────┤
│ Patched versions │ >=2.4.0 │
├─────────────────────┼─────────────────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-fxwf-4rqh-v8g3 │
└─────────────────────┴─────────────────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ moderate │ Tmp files readable by other users in sync-exec │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ sync-exec │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <=0.6.2 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ <0.0.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-38h8-x697-gh8q │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ moderate │ Prototype Pollution in hoek │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ hoek │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <4.2.1 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=4.2.1 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-jp4x-w63m-7wgm │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ moderate │ json-schema is vulnerable to Prototype Pollution │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ json-schema │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <0.4.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=0.4.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-896r-f27r-55mw │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ moderate │ Header injection in nodemailer │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ nodemailer │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <6.6.1 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=6.6.1 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-hwqf-gcqm-7353 │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ moderate │ Incorrect Default Permissions in log4js │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ log4js │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <6.4.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=6.4.0 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-82v2-mx6x-wq7q │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ moderate │ Regular Expression Denial of Service (ReDoS) in lodash │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package │ lodash │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <4.17.21 │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions │ >=4.17.21 │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-29mw-wpgm-hmr9 │
└─────────────────────┴────────────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ moderate │ Cross-site Scripting in karma │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ karma │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <6.3.14 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=6.3.14 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-7x7c-qm48-pq9c │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬───────────────────────────────────────────────────┐
│ moderate │ Prototype Pollution in Ajv │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Package │ ajv │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Vulnerable versions │ <6.12.3 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ Patched versions │ >=6.12.3 │
├─────────────────────┼───────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-v88g-cgmw-v5xw │
└─────────────────────┴───────────────────────────────────────────────────┘
┌─────────────────────┬────────────────────────────────────────────────────────────────────────────────┐
│ moderate │ Exposure of Sensitive Information to an Unauthorized Actor in follow-redirects │
├─────────────────────┼────────────────────────────────────────────────────────────────────────────────┤
│ Package │ follow-redirects │
├─────────────────────┼────────────────────────────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <1.14.8 │
├─────────────────────┼────────────────────────────────────────────────────────────────────────────────┤
│ Patched versions │ >=1.14.8 │
├─────────────────────┼────────────────────────────────────────────────────────────────────────────────┤
│ More info │ https://github.com/advisories/GHSA-pw2r-vq6v-hr8c │
└─────────────────────┴────────────────────────────────────────────────────────────────────────────────┘
46 vulnerabilities found
Severity: 4 low | 17 moderate | 21 high | 4 critical"
`;

View File

@@ -2,6 +2,7 @@ import path from 'path'
import { fixtures } from '@pnpm/test-fixtures'
import { ProjectManifest } from '@pnpm/types'
import { audit } from '@pnpm/plugin-commands-audit'
import { readProjectManifest } from '@pnpm/read-project-manifest'
import loadJsonFile from 'load-json-file'
import nock from 'nock'
import * as responses from './utils/responses'
@@ -57,3 +58,43 @@ test('no overrides are added if no vulnerabilities are found', async () => {
expect(exitCode).toBe(0)
expect(output).toBe('No fixes were made')
})
test('CVEs found in the allow list are not added as overrides', async () => {
const tmp = f.prepare('has-vulnerabilities')
{
const { manifest, writeProjectManifest } = await readProjectManifest(tmp)
manifest.pnpm = {
...manifest.pnpm,
auditConfig: {
ignoreCves: [
'CVE-2019-10742',
'CVE-2020-28168',
'CVE-2021-3749',
'CVE-2020-7598',
],
},
}
await writeProjectManifest(manifest)
}
nock(registries.default)
.post('/-/npm/v1/security/audits')
.reply(200, responses.ALL_VULN_RESP)
const { exitCode, output } = await audit.handler({
auditLevel: 'moderate',
dir: tmp,
fix: true,
userConfig: {},
rawConfig,
registries,
})
expect(exitCode).toBe(0)
expect(output).toMatch(/Run "pnpm install"/)
const manifest = await loadJsonFile<ProjectManifest>(path.join(tmp, 'package.json'))
expect(manifest.pnpm?.overrides?.['axios@<=0.18.0']).toBeFalsy()
expect(manifest.pnpm?.overrides?.['axios@<0.21.1']).toBeFalsy()
expect(manifest.pnpm?.overrides?.['minimist@<0.2.1']).toBeFalsy()
expect(manifest.pnpm?.overrides?.['url-parse@<1.5.6']).toBeTruthy()
})

View File

@@ -1,10 +1,12 @@
import path from 'path'
import { fixtures } from '@pnpm/test-fixtures'
import { audit } from '@pnpm/plugin-commands-audit'
import { AuditEndpointNotExistsError } from '@pnpm/audit'
import nock from 'nock'
import stripAnsi from 'strip-ansi'
import * as responses from './utils/responses'
const f = fixtures(path.join(__dirname, 'fixtures'))
const registries = {
default: 'https://registry.npmjs.org/',
}
@@ -171,3 +173,34 @@ test('audit endpoint does not exist', async () => {
registries,
})).rejects.toThrow(AuditEndpointNotExistsError)
})
test('audit: CVEs in ignoreCves do not show up', async () => {
const tmp = f.prepare('has-vulnerabilities')
nock(registries.default)
.post('/-/npm/v1/security/audits')
.reply(200, responses.ALL_VULN_RESP)
const { exitCode, output } = await audit.handler({
auditLevel: 'moderate',
dir: tmp,
userConfig: {},
rawConfig,
registries,
rootProjectManifest: {
pnpm: {
auditConfig: {
ignoreCves: [
'CVE-2019-10742',
'CVE-2020-28168',
'CVE-2021-3749',
'CVE-2020-7598',
],
},
},
},
})
expect(exitCode).toBe(1)
expect(stripAnsi(output)).toMatchSnapshot()
})

View File

@@ -134,6 +134,9 @@ export type ProjectManifest = BaseManifest & {
updateConfig?: {
ignoreDependencies?: string[]
}
auditConfig?: {
ignoreCves?: string[]
}
}
private?: boolean
resolutions?: Record<string, string>