npm-supply-chain-audit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesenpm supply-chain security audit
npm供应链安全审计
Audit the current repo for npm supply-chain security issues, present findings to the user, and apply fixes only after confirmation.
审计当前仓库中的npm供应链安全问题,向用户呈现检测结果,并仅在用户确认后应用修复。
Step 1 – Detect the package manager
步骤1 – 检测包管理器
Check which package manager(s) are in use:
- -> npm
package-lock.json - -> Aube
aube-lock.yaml - -> pnpm
pnpm-lock.yaml - +
yarn.lock-> Yarn Berry;.yarnrc.ymlwithoutyarn.lock-> Yarn Classic.yarnrc.yml - or
bun.lockb-> Bunbun.lock - field in
packageManagerconfirms the PM and versionpackage.json
Use the field to determine the version. If not present, run the PM's command. The version is needed for checks that depend on minimum PM versions (e.g. pnpm 10+, pnpm 11+, npm 11.10+, Yarn Berry 4.10+, Bun 1.3+).
packageManager--versionpnpm 11 ships several supply-chain protections on by default (, , ) and only reads pnpm-specific settings from (or ), not from . Many checks below differ between pnpm 10 and pnpm 11+.
minimumReleaseAge: 1440blockExoticSubdeps: truestrictDepBuilds: truepnpm-workspace.yaml~/.config/pnpm/config.yaml.npmrcIf no lockfile exists, default to npm.
检查当前使用的包管理器:
- -> npm
package-lock.json - -> Aube
aube-lock.yaml - -> pnpm
pnpm-lock.yaml - +
yarn.lock-> Yarn Berry;无.yarnrc.yml的.yarnrc.yml-> Yarn Classicyarn.lock - 或
bun.lockb-> Bunbun.lock - 中的
package.json字段可确认包管理器及其版本packageManager
使用字段确定版本。如果该字段不存在,运行包管理器的命令。版本信息对依赖最低版本的检查是必需的(例如pnpm 10+、pnpm 11+、npm 11.10+、Yarn Berry 4.10+、Bun 1.3+)。
packageManager--versionpnpm 11默认启用多项供应链防护(、、),且仅从(或)读取pnpm特定设置,而非。以下许多检查在pnpm 10和pnpm 11+之间存在差异。
minimumReleaseAge: 1440blockExoticSubdeps: truestrictDepBuilds: truepnpm-workspace.yaml~/.config/pnpm/config.yaml.npmrc如果不存在锁文件,默认使用npm。
Step 2 – Audit
步骤2 – 审计
Work through the checks below. For each one, check the current state and record whether it passes or needs a fix. Do NOT make any changes yet.
执行以下检查。对于每一项,检查当前状态并记录是否通过或需要修复。请勿进行任何修改。
2.1 Lockfile committed
2.1 已提交锁文件
If no lockfile exists (, , , , , ), warn the user they should run their package manager's install command and commit the lockfile. Do NOT run install yourself.
package-lock.jsonpnpm-lock.yamlyarn.lockbun.lockbbun.lockaube-lock.yaml如果不存在锁文件(、、、、、),提醒用户应运行包管理器的install命令并提交锁文件。请勿自行运行install。
package-lock.jsonpnpm-lock.yamlyarn.lockbun.lockbbun.lockaube-lock.yaml2.2 Block lifecycle scripts
2.2 拦截生命周期脚本
npm – ensure contains:
.npmrcini
ignore-scripts=truepnpm 10+ – blocks lifecycle scripts by default. Check that does NOT set . If it does, warn the user. pnpm 11+ additionally enables by default, so installs error (rather than just warn) when a dependency wants to run a build script that isn't in the allowlist – verify it has not been disabled in .
pnpm-workspace.yamldangerouslyAllowAllBuilds: truestrictDepBuilds: truepnpm-workspace.yamlpnpm <= 9 – ensure contains .
.npmrcignore-scripts=trueYarn Classic (v1) – ensure contains .
.npmrcignore-scripts=trueYarn Berry (v2+) – ensure contains:
.yarnrc.ymlyaml
enableScripts: falseBun – blocks lifecycle scripts by default. No action needed.
Aube – blocks lifecycle scripts by default. Check that does NOT set . If it does, warn the user.
aube-workspace.yamldangerouslyAllowAllBuilds: truenpm – 确保包含:
.npmrcini
ignore-scripts=truepnpm 10+ – 默认拦截生命周期脚本。检查是否未设置。如果已设置,提醒用户。pnpm 11+额外默认启用,因此当依赖想要运行不在允许列表中的构建脚本时,安装会报错(而非仅警告)——需验证该设置未在中被禁用。
pnpm-workspace.yamldangerouslyAllowAllBuilds: truestrictDepBuilds: truepnpm-workspace.yamlpnpm <= 9 – 确保包含。
.npmrcignore-scripts=trueYarn Classic (v1) – 确保包含。
.npmrcignore-scripts=trueYarn Berry (v2+) – 确保包含:
.yarnrc.ymlyaml
enableScripts: falseBun – 默认拦截生命周期脚本。无需操作。
Aube – 默认拦截生命周期脚本。检查是否未设置。如果已设置,提醒用户。
aube-workspace.yamldangerouslyAllowAllBuilds: true2.3 Build script allowlists
2.3 构建脚本允许列表
When lifecycle scripts are blocked, some packages legitimately need build scripts. Check the lockfile for packages that require builds:
- pnpm – look for entries with in
requiresBuild: truepnpm-lock.yaml - npm – look for in
hasInstallScript: truepackage-lock.json - Yarn Berry – look for or build-related metadata in
hasBinyarn.lock - Bun – check for packages with lifecycle scripts
bun.lock
Compare the list of packages that require builds against the current allowlist. Report any that are missing, but do NOT suggest adding them blindly – the user must verify each package is trusted before allowlisting it. Only well-known packages from reputable maintainers (e.g. , , ) should be considered.
esbuildsharp@swc/coreThe allowlist setting per package manager:
pnpm 11+ – map in . This replaces , , , and , which are no longer supported:
allowBuildspnpm-workspace.yamlonlyBuiltDependenciesonlyBuiltDependenciesFileneverBuiltDependenciesignoredBuiltDependenciesyaml
allowBuilds:
esbuild: true
core-js: falsepnpm 10 / Aube – in / :
onlyBuiltDependenciespnpm-workspace.yamlaube-workspace.yamlyaml
onlyBuiltDependencies:
- esbuildYarn Berry – in :
dependenciesMetapackage.jsonjson
"dependenciesMeta": {
"esbuild": { "built": true }
}Bun – in :
trustedDependenciespackage.jsonjson
"trustedDependencies": ["esbuild"]当生命周期脚本被拦截时,部分包确实需要构建脚本。检查锁文件中需要构建的包:
- pnpm – 在中查找带有
pnpm-lock.yaml的条目requiresBuild: true - npm – 在中查找
package-lock.jsonhasInstallScript: true - Yarn Berry – 在中查找
yarn.lock或与构建相关的元数据hasBin - Bun – 在中检查带有生命周期脚本的包
bun.lock
将需要构建的包列表与当前允许列表进行对比。报告任何缺失的包,但请勿盲目建议添加——用户必须先验证每个包是否可信,再将其加入允许列表。仅应考虑来自知名维护者的知名包(例如、、)。
esbuildsharp@swc/core各包管理器的允许列表设置:
pnpm 11+ – 中的映射。该设置替代了不再受支持的、、和:
pnpm-workspace.yamlallowBuildsonlyBuiltDependenciesonlyBuiltDependenciesFileneverBuiltDependenciesignoredBuiltDependenciesyaml
allowBuilds:
esbuild: true
core-js: falsepnpm 10 / Aube – / 中的:
pnpm-workspace.yamlaube-workspace.yamlonlyBuiltDependenciesyaml
onlyBuiltDependencies:
- esbuildYarn Berry – 中的:
package.jsondependenciesMetajson
"dependenciesMeta": {
"esbuild": { "built": true }
}Bun – 中的:
package.jsontrustedDependenciesjson
"trustedDependencies": ["esbuild"]2.4 Release-age cooldown
2.4 发布冷却期
Check if a release-age cooldown is configured. If not, recommend adding one. If already configured, note the current value. When presenting findings, advise the user that 3 days is a good minimum. Mention that 7 days provides stronger protection but slows down updates.
The setting per package manager:
npm 11.10+ – in (value in days):
min-release-age.npmrcini
min-release-age=3pnpm 10.16+ – in (value in minutes):
minimumReleaseAgepnpm-workspace.yamlyaml
minimumReleaseAge: 4320pnpm 11+ – defaults to (1 day). The repo is already protected, but recommend overriding to a stronger value (e.g. for 3 days or for 7 days). Also verify the default has not been disabled with .
minimumReleaseAge: 1440432010080minimumReleaseAge: 0Also check if contains a setting – this is a common mistake. pnpm only reads this setting from , not (and pnpm 11+ does not read any pnpm-specific settings from at all). If found, warn the user and suggest moving it to .
.npmrcminimumReleaseAgepnpm-workspace.yaml.npmrc.npmrcpnpm-workspace.yamlYarn Berry 4.10+ – in (value in minutes):
npmMinimalAgeGate.yarnrc.ymlyaml
npmMinimalAgeGate: 4320Bun 1.3+ – in (value in seconds):
minimumReleaseAgebunfig.tomltoml
[install]
minimumReleaseAge = 259200Aube – defaults to 1440 minutes (1 day). in (value in minutes):
minimumReleaseAgeaube-workspace.yamlyaml
minimumReleaseAge: 4320检查是否配置了发布冷却期。如果未配置,建议添加。如果已配置,记录当前值。呈现检测结果时,建议用户设置至少3天的冷却期。说明7天的冷却期防护更强,但会减慢更新速度。
各包管理器的设置:
npm 11.10+ – 中的(单位:天):
.npmrcmin-release-ageini
min-release-age=3pnpm 10.16+ – 中的(单位:分钟):
pnpm-workspace.yamlminimumReleaseAgeyaml
minimumReleaseAge: 4320pnpm 11+ – 默认设置为(1天)。仓库已受防护,但建议覆盖为更强的设置(例如代表3天,代表7天)。同时验证默认设置未被禁用。
minimumReleaseAge: 1440432010080minimumReleaseAge: 0还要检查是否包含设置——这是常见错误。pnpm仅从读取该设置,而非(且pnpm 11+完全不从读取任何pnpm特定设置)。如果发现该设置,提醒用户并建议将其移至。
.npmrcminimumReleaseAgepnpm-workspace.yaml.npmrc.npmrcpnpm-workspace.yamlYarn Berry 4.10+ – 中的(单位:分钟):
.yarnrc.ymlnpmMinimalAgeGateyaml
npmMinimalAgeGate: 4320Bun 1.3+ – 中的(单位:秒):
bunfig.tomlminimumReleaseAgetoml
[install]
minimumReleaseAge = 259200Aube – 默认设置为1440分钟(1天)。中的(单位:分钟):
aube-workspace.yamlminimumReleaseAgeyaml
minimumReleaseAge: 43202.5 Block exotic subdeps (pnpm / Aube)
2.5 拦截外来子依赖(pnpm / Aube)
pnpm 10 – ensure contains:
pnpm-workspace.yamlyaml
blockExoticSubdeps: truepnpm 11+ / Aube – defaults to true. Verify it has not been explicitly disabled in / .
pnpm-workspace.yamlaube-workspace.yamlThis prevents transitive dependencies from using git or tarball URLs.
pnpm 10 – 确保包含:
pnpm-workspace.yamlyaml
blockExoticSubdeps: truepnpm 11+ / Aube – 默认设置为true。验证该设置未在 / 中被显式禁用。
pnpm-workspace.yamlaube-workspace.yaml此设置可防止传递依赖使用git或tarball URL。
2.6 Trust policy (pnpm / Aube)
2.6 信任策略(pnpm / Aube)
pnpm / Aube – ensure or contains:
pnpm-workspace.yamlaube-workspace.yamlyaml
trustPolicy: no-downgradeThis blocks packages whose trust level has decreased.
pnpm / Aube – 确保或包含:
pnpm-workspace.yamlaube-workspace.yamlyaml
trustPolicy: no-downgrade此设置可阻止信任级别降低的包。
2.7 Hardened mode (Yarn Berry only)
2.7 强化模式(仅Yarn Berry)
If using Yarn Berry, ensure contains:
.yarnrc.ymlyaml
enableHardenedMode: trueThis validates the lockfile against the registry.
如果使用Yarn Berry,确保包含:
.yarnrc.ymlyaml
enableHardenedMode: true此设置会验证锁文件与注册表的一致性。
2.8 Dependency update cooldown (Renovate / Dependabot)
2.8 依赖更新冷却期(Renovate / Dependabot)
Check if the repo uses Renovate or Dependabot and whether a cooldown is configured.
Renovate – look for config in , , , , , , or a key in . Check if the array includes any of the following (all of which include a 3-day npm cooldown):
renovate.jsonrenovate.json5.github/renovate.json.github/renovate.json5.renovaterc.renovaterc.json"renovate"package.jsonextends"config:best-practices""security:minimumReleaseAgeNpm"- (the Nitor recommended preset extends
"NitorCreations/renovate-config:recommended")config:best-practices
Also check shared presets – if references another custom preset (e.g. ), note that the cooldown may already be configured there and the user should verify.
extends"local>myorg/renovate-config"If Renovate config exists but doesn't include any of the above presets, suggest adding :
security:minimumReleaseAgeNpmjson
{ "extends": ["security:minimumReleaseAgeNpm"] }Dependabot – look for . Check if npm ecosystem entries have a configured. If not, suggest adding:
.github/dependabot.ymlcooldownyaml
cooldown:
default-days: 3If neither Renovate nor Dependabot is configured, skip this check – don't add a dependency update tool unprompted.
检查仓库是否使用Renovate或Dependabot,以及是否配置了冷却期。
Renovate – 在、、、、、或中的键中查找配置。检查数组是否包含以下任一预设(均包含3天的npm冷却期):
renovate.jsonrenovate.json5.github/renovate.json.github/renovate.json5.renovaterc.renovaterc.jsonpackage.json"renovate"extends"config:best-practices""security:minimumReleaseAgeNpm"- (Nitor推荐预设继承自
"NitorCreations/renovate-config:recommended")config:best-practices
同时检查共享预设——如果引用了其他自定义预设(例如),说明冷却期可能已在该预设中配置,用户需自行验证。
extends"local>myorg/renovate-config"如果存在Renovate配置但未包含上述任一预设,建议添加:
security:minimumReleaseAgeNpmjson
{ "extends": ["security:minimumReleaseAgeNpm"] }Dependabot – 查找。检查npm生态系统条目是否配置了。如果未配置,建议添加:
.github/dependabot.ymlcooldownyaml
cooldown:
default-days: 3如果未配置Renovate或Dependabot,跳过此检查——请勿未经提示添加依赖更新工具。
Step 3 – Present findings
步骤3 – 呈现检测结果
Present a summary of the audit results to the user:
- Start with a one-line summary count (e.g. "3 passing, 4 need fixes")
- List checks that already pass as bullet points (not numbered) – keep these brief
- List checks that need fixes, with the specific changes that would be made
- List any issues that require manual action (e.g. missing lockfile, )
dangerouslyAllowAllBuilds - When multiple fixes target the same file, show a combined preview of the full proposed file content at the end
- Do not use horizontal rules () – headings provide enough structure
---
IMPORTANT formatting rules – follow exactly:
- Use a numbered list for fixes. Put ALL explanation BEFORE the code block.
- Every proposed config change MUST be wrapped in a fenced code block using triple backticks and a language tag (e.g. yaml, json, toml, ini). RAW config text without triple-backtick fences is WRONG and hard to read.
- Indent code blocks with 3 spaces so they are nested inside the list item. This is critical – without the indent, the code block breaks out of the list and the numbering restarts (causing duplicate numbers like 1, 1, 2, 2).
- Leave a blank line before the opening triple backticks and after the closing triple backticks.
Then ask the user for confirmation before proceeding.
向用户呈现审计结果摘要:
- 开头用一行总结检测结果数量(例如“3项通过,4项需要修复”)
- 用无序列表列出已通过的检查——保持简洁
- 列出需要修复的检查,以及具体的修改方案
- 列出需要手动操作的问题(例如缺失锁文件、设置)
dangerouslyAllowAllBuilds - 当多个修复针对同一文件时,在末尾展示完整的拟修改文件内容预览
- 请勿使用水平分隔线()——标题已提供足够的结构
---
重要格式规则——严格遵循:
- 使用有序列表列出修复方案。所有说明文字需放在代码块之前。
- 所有拟议的配置修改必须用三重反引号和语言标签(例如yaml、json、toml、ini)包裹在代码块中。未使用三重反引号的原始配置文本是错误的,且难以阅读。
- 代码块缩进3个空格,使其嵌套在列表项内。这一点至关重要——如果没有缩进,代码块会跳出列表,导致编号重新开始(出现1、1、2、2等重复编号)。
- 在开头的三重反引号前和结尾的三重反引号后各留一个空行。
然后请求用户确认后再继续。
Step 4 – Apply fixes
步骤4 – 应用修复
After the user confirms, apply the agreed-upon changes. If the user wants to skip certain fixes, respect that. Summarize what was changed.
用户确认后,应用商定的修改。如果用户希望跳过某些修复,需尊重其选择。总结已修改的内容。