[BUG] allowScripts doesn't stop a git dependency's prepare script
维护者通常 2 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 56/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, node.js
调研方向
Start with the cited allowScripts check in workspaces/arborist/lib/arborist/rebuild.js and trace how git dependencies reach pacote's prepare step in pacote/lib/dir.js. Compare the existing isScriptAllowed() and ignoreScripts handling, then add or update tests for a disallowed git dependency and an allowed one. Done means a disallowed prepare script never runs during npm install, while allowed scripts retain their expected behavior.
由索引模型根据 Issue 内容生成。
描述
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
This is not just a request to bump a dependency for a CVE
- This is not solely a request to bump a dependency for a CVE
Current Behavior
With allow-git on, a git dependency's prepare runs during a plain npm install even though the package isn't in allowScripts. npm then warns that it blocked the script, after it has already run.
The allowScripts check is in Arborist's rebuild queue, which runs after extraction:
https://github.com/npm/cli/blob/60e11343e61316d966c86805d803df5a0eb99230/workspaces/arborist/lib/arborist/rebuild.js#L212-L215
A git dependency's prepare runs before that, while pacote packs the clone, and the only gate there is ignoreScripts:
https://github.com/npm/pacote/blob/453a0adac3592e5f93c8f782fb1b1b320ac95009/lib/dir.js#L38-L40
--strict-allow-scripts checks the tree before extraction, so it does stop it (ESTRICTALLOWSCRIPTS, the script never starts).
Expected Behavior
A git dependency that allowScripts doesn't allow doesn't run prepare, e.g. by extracting it with ignoreScripts: true when isScriptAllowed() isn't true for that node.
Steps To Reproduce
$ mkdir evil-gitdep && cd evil-gitdep
$ echo '{ "name": "evil-gitdep", "version": "1.0.0", "scripts": { "prepare": "node evil.js" } }' > package.json
$ echo 'require("fs").writeFileSync("/tmp/pwned", "pwned"); console.log("PREPARE_RAN")' > evil.js
$ git init -q && git add -A && git commit -qm init && cd ..
$ mkdir app && cd app
$ printf '{ "name": "app", "version": "1.0.0", "dependencies": { "evil-gitdep": "git+file://%s/evil-gitdep" } }\n' "$(cd .. && pwd)" > package.json
$ echo 'allow-git=all' > .npmrc
$ npm install --foreground-scripts
npm notice run [email protected] prepare
npm notice run node evil.js
PREPARE_RAN
added 1 package in 989ms
npm warn install-scripts 1 package had install scripts blocked because they are not covered by allowScripts:
npm warn install-scripts [email protected] (prepare: node evil.js)
[..]
$ cat /tmp/pwned
pwned
--foreground-scripts only makes the order visible; the script runs without it too.
Environment
- npm: 12.2.2
- Node.js: 24.22.1
- OS Name: macOS 26
- npm config:
allow-git=all(project.npmrc)
- 主要语言
- JavaScript
- 星标
- 10.3k
- 派生
- 5k
- 平均合并
- 4 天 11 小时
- 30 天内合并 PR
- 26
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
npm/cli 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 2 天内回复
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endings可能已有人在做 @saruk-vedant 于 7 天前认领。 未关闭Bug Needs Triage Triage Requested
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 2 天内回复
-
[BUG] npm pkg delete removes the first array item for a nonexistent property可能已有人在做 @drawliin 于 42 天前认领。 未关闭cmd:delete Priority 3
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 2 天内回复
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings logged可能重新可做 关联的 PR 已关闭且未合并。 未关闭Engineering Priority 1
难度 1/5 1 小时以内 新手友好度 80/100
维护者通常 2 天内回复
-
`npm audit signatures` does not report how many packages it skipped for want of registry keys可能已有人在做 @greenlincoln05 于 63 天前认领。 未关闭Priority 3
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 2 天内回复
相似的 Issue
-
docs: add SECURITY.md vulnerability reporting policy可能已有人在做 @AK-Lmn 今天认领。 未关闭
难度 1/5 1-3 小时 新手友好度 72/100
flisk-sh/linux2wasm#12 ·
维护者通常 1 天内回复
-
possible bug
难度 2/5 1-3 小时 新手友好度 84/100
Mintplex-Labs/anything-llm#7388 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 60/100
维护者通常 1 天内回复
-
v6: Minified bootstrap.min.css is missing header info可能已有人在做 @lazerg 今天认领。 未关闭bug build confirmed has-pr v6
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
[workshop-sync] workshop/side-quest-26-01-forecast-costs.md: forecast default history window is inaccurate可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭documentation
难度 1/5 1 小时以内 新手友好度 88/100
githubnext/gh-aw-workshop#6332 ·
维护者通常 1 天内回复