pnpm audit
检查已安装程序包的已知安全问题。
如果发现安全问题,请尝试通过 pnpm update 更新你的依赖项。如果简单的更新不能解决所有问题,请使用 overrides 强制使用不易受攻击的版本。例如,如果 lodash@<2.1.0 易受攻击,可用这个 overrides 来强制使用 lodash@^2.1.0:
overrides:
"lodash@<2.1.0": "^2.1.0"
或者运行 pnpm audit --fix。
如果你想容忍一些不影响项目的漏洞,可以使用 audit.ignore 设置。
pnpm audit queries the registry's /-/npm/v1/security/advisories/bulk endpoint. The response does not include CVE identifiers, so advisories are identified by the GitHub advisory ID (GHSA) in their URL.
The command exits with code 1 when an advisory at or above the audit level remains after ignored advisories are removed. This also applies to --ignore and --ignore-unfixable, which save the IDs first.
命令#
signatures#
pnpm audit signatures
Verifies the ECDSA registry signatures of installed registry packages against the public keys each registry publishes at /-/npm/v1/keys. pnpm respects scoped and prefix-routed registries configured via registries, and skips registries that do not publish signing keys as well as tarball, git, and directory dependencies.
Signatures are verified against the package integrity recorded in the lockfile. A package without recorded integrity cannot pass verification.
A registry signs the integrity of a package's .tgz. When the lockfile pins tars with lockfile.integrityTarget: tar, the signature is verified against the .tgz integrity the registry publishes, once pnpm has tied it to the tar hash in the lockfile. The store answers for a package it holds. Any other package is downloaded and checked. A package that cannot be tied is reported as invalid, with the reason.
如果任何软件包的签名无效,或者注册源声明了签名密钥,但发布的软件包没有签名,则该命令将以代码 1 退出。结合使用 --json 参数可获得机器可读的输出。
deprecations#
pnpm audit deprecations
Lists the installed packages that their registry marks as deprecated, with the message the publisher left. Each package shows the projects that depend on it directly, or a chain of packages that brings it in. When the package has a version that is not deprecated, the newest one is named.
pnpm reads registry metadata from its cache when that metadata is less than 5 minutes old, so right after an install no requests are needed. Older metadata is checked against the registry, so a package deprecated since then is reported. Tarball, git, and directory dependencies are skipped.
The command exits with code 1 if any installed package is deprecated. --prod, --dev, --no-optional, --json, --ignore-registry-errors, and workspace filters apply to it.
engines#
pnpm audit engines
Lists the installed packages that don't support the current Node.js version or platform, with what each one wants. Each package shows the projects that depend on it directly, or a chain of packages that brings it in. These are the packages an install warns about.
pnpm checks the packages against the Node.js version an install uses: the nodeVersion setting, the Node.js version the lockfile pins for the root project, or the system Node.js. The platform includes supportedArchitectures. An optional dependency that an install skips is not listed. The command reads the lockfile and makes no registry requests.
The command exits with code 1 if any installed package is incompatible. --prod, --dev, --no-optional, --json, and workspace filters apply to it.
配置项#
--audit-level <severity>#
- Type: info, low, moderate, high, critical
- 默认值:low
仅打印严重性大于或等于 "severity" 的警告。 Advisories below this level also do not fail the command.
这也可以通过 pnpm-workspace.yaml 中的 audit.level 来设置。
--fix#
Add overrides to the pnpm-workspace.yaml file to force non-vulnerable versions of the dependencies.
Use --fix=update to fix vulnerabilities by updating the vulnerable packages in the lockfile instead of adding overrides.
When minimumReleaseAge would block the minimum patched version, --fix adds it to minimumReleaseAgeExclude in pnpm-workspace.yaml so it can be installed.
--no-add-release-age-exclusions#
Skip automatic additions to minimumReleaseAgeExclude for both fix methods and interactive fixes. The release age policy can still block recently published patches unless an existing exclusion allows them. If the resolver selects a patch that the age policy blocks, --fix=update can exit with ERR_PNPM_NO_MATURE_MATCHING_VERSION. With --fix=update, the update still follows minimumReleaseAgeExcludePrune.
--interactive, -i#
审查 --fix 选择的建议,并选择要应用的建议。 Implies --fix=override when --fix is not given.
--json#
以 JSON 格式输出审查报告。
patched_versions is null for an advisory with no published fix, so tooling can tell "no fix available" from "fix available at version X".
--dev, -D#
仅审查开发依赖项。
--prod, --production, -P#
Only audit dependencies and optionalDependencies.
--optional#
Audit optionalDependencies. 这是默认值。
--no-optional#
不审查 optionalDependencies。
--ignore-registry-errors#
如果注册源响应了非 200 状态码,则进程应以 0 退出。所以只有当注册源真正成功响应发现的漏洞时,该进程才会执行失败。
--ignore-unfixable#
忽略所有没有解决方式的警报。 An unfixable advisory without a GHSA ID cannot be ignored and fails the command with ERR_PNPM_AUDIT_MISSING_GHSA.
Their GHSA IDs are saved in pnpm-workspace.yaml the same way as with --ignore.
--ignore <vulnerability>#
按 GitHub 公告 ID (GHSA) 忽略漏洞。
The ID is saved in pnpm-workspace.yaml, which is created if missing, and no audit report is printed. It is added to audit.ignore if that list is already set, otherwise to the deprecated auditConfig.ignoreGhsas, which pnpm still reads. To have a new project write to audit.ignore, create the list first (audit: { ignore: [] }).
配置#
pnpm audit is configured in the audit section of pnpm-workspace.yaml:
audit:
level: high
ignore:
- GHSA-42xw-2xvc-qx8m
audit.level#
- 默认值:low
- Type: info, low, moderate, high, critical
仅打印严重程度等于或高于此级别的警告。等同于 --audit-level 标志。
audit.ignore#
会被 pnpm audit 命令忽略的 GHSA 代码列表。
audit:
ignore:
- GHSA-42xw-2xvc-qx8m
- GHSA-4w2v-q235-vp99
- GHSA-cph5-m8f7-6c5x
- GHSA-vh95-rmgr-6w4m
Since v12.4.0, ignored advisories are left out of the vulnerability total and the per-severity counts, and reported separately. When every advisory found is ignored, the summary says so rather than reporting a clean audit.
audit.ignorePrune#
添加于:v12.0.0
- 默认值: false
- 类型:Boolean
When true, pnpm audit --fix removes the audit.ignore
entries whose GHSA no longer appears in the audit report, so a list of tolerated
advisories doesn't accumulate entries for dependencies that are long gone.
audit:
ignorePrune: true
提示
auditLevel and auditConfig.ignoreGhsas are deprecated names for audit.level and audit.ignore, and pnpm still reads them. When both spellings are set, the audit section takes precedence and a warning is printed.
auditConfig.ignoreCves is not recognized. Replace each CVE with the matching GHSA-xxxx-xxxx-xxxx ID, shown in the More info column of pnpm audit output, under audit.ignore.