pnpm audit
检查已安装软件包的已知安全问题。
🌐 Checks for known security issues with the installed packages.
如果发现安全问题,请尝试通过 pnpm update 更新你的依赖。如果简单更新不能解决所有问题,请使用 overrides 强制使用不易受攻击的版本。例如,如果 lodash@<2.1.0 存在漏洞,请使用此 overrides 强制使用 lodash@^2.1.0:
🌐 If security issues are found, try to update your dependencies via pnpm update.
If a simple update does not fix all the issues, use overrides to force
versions that are not vulnerable. For instance, if lodash@<2.1.0 is vulnerable,
use this overrides to force lodash@^2.1.0:
overrides:
"lodash@<2.1.0": "^2.1.0"
或者,运行 pnpm audit --fix。
🌐 Or alternatively, run pnpm audit --fix.
如果你想容忍一些对项目没有影响的漏洞,可以使用 auditConfig.ignoreCves 设置。
🌐 If you want to tolerate some vulnerabilities as they don't affect your project, you may use the auditConfig.ignoreCves setting.
选项
🌐 Options
--audit-level <severity>
- 类型:低、中、高、严重
- 默认:低
仅打印严重性大于或等于 <severity> 的通知。
🌐 Only print advisories with severity greater than or equal to <severity>.
这也可以通过在 pnpm-workspace.yaml 中设置 auditLevel 来实现。
🌐 This can also be set via auditLevel in pnpm-workspace.yaml.
--fix
在 package.json 文件中添加覆盖项,以强制使用非漏洞版本的依赖。
🌐 Add overrides to the package.json file in order to force non-vulnerable versions of the dependencies.
--json
以 JSON 格式输出审计报告。
🌐 Output audit report in JSON format.
--dev, -D
仅审核开发依赖。
🌐 Only audit dev dependencies.
--prod, -P
仅审核生产依赖。
🌐 Only audit production dependencies.
--no-optional
不要审核 optionalDependencies。
🌐 Don't audit optionalDependencies.
--ignore-registry-errors
如果注册表返回非 200 状态码,进程应以 0 退出。 所以只有当注册表实际上成功返回发现的漏洞时,进程才会失败。
🌐 If the registry responds with a non-200 status code, the process should exit with 0. So the process will fail only if the registry actually successfully responds with found vulnerabilities.
--ignore-unfixable
新增于:v10.11.0
🌐 Added in: v10.11.0
忽略所有未解决的 CVE。
🌐 Ignore all CVEs with no resolution.
--ignore <vulnerability>
新增于:v10.11.0
🌐 Added in: v10.11.0
忽略 CVE 漏洞。
🌐 Ignore a vulnerability by CVE.
配置
🌐 Configuration
auditConfig
auditConfig.ignoreCves
将被 pnpm audit 命令忽略的 CVE ID 列表。
🌐 A list of CVE IDs that will be ignored by the pnpm audit command.
auditConfig:
ignoreCves:
- CVE-2022-36313
auditConfig.ignoreGhsas
将被 pnpm audit 命令忽略的 GHSA 代码列表。
🌐 A list of GHSA Codes that will be ignored by the pnpm audit command.
auditConfig:
ignoreGhsas:
- GHSA-42xw-2xvc-qx8m
- GHSA-4w2v-q235-vp99
- GHSA-cph5-m8f7-6c5x
- GHSA-vh95-rmgr-6w4m