[BUG] `npm install-scripts approve` saves an absolute path for a local tarball dependency, so the approval breaks on other machines
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 半天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, nodejs
- 领域
- tooling
调研方向
Start with the npm install-scripts approve command and the allowScripts keys it writes to package.json, then reproduce with the script in the issue, which copies the project to a new folder and reinstalls. Draft PR #9794 is cited as already changing how these keys are written, so read it first to see what it does. Done means approved local tarball keys are project-relative, like file:../tgzdep-1.0.0.tgz, and both postinstall scripts still run in the moved copy.
由索引模型根据 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
When you approve the install script of a dependency installed from a local tarball, npm install-scripts approve saves the tarball's absolute path as the allowScripts key:
"allowScripts": {
"file:../../dirdep": true,
"file:C:\\Users\\<user>\\work\\tgzdep-1.0.0.tgz": true
}
That key only matches on the machine and in the folder where it was approved. After a clone, on CI, or when the project is moved, the approval no longer applies and the script is blocked again:
npm warn install-scripts 1 package had install scripts blocked because they are not covered by allowScripts:
npm warn install-scripts [email protected] (postinstall: ...)
It also commits the approver's local username and folder layout into package.json.
A local directory dependency approved the same way keeps working after the move. Its key (file:../../dirdep) is relative, although it's relative to node_modules rather than to the project, unlike the file:../dirdep spec in dependencies.
Expected Behavior
npm install-scripts approve saves a key relative to the project, like the spec in dependencies (file:../tgzdep-1.0.0.tgz, file:../dirdep), so a committed approval keeps working on every machine.
I checked out draft PR #9794 and ran the same steps with it. It saves file:../dirdep and file:../tgzdep-1.0.0.tgz, and both scripts run in the moved copy. So #9794 appears to fix this, and this issue gives it a user-facing repro.
Steps To Reproduce
mkdir proj dirdep tgzsrc
echo '{"name":"dirdep","version":"1.0.0","scripts":{"postinstall":"node -e \"require(`fs`).writeFileSync(`ran`,``)\""}}' > dirdep/package.json
echo '{"name":"tgzdep","version":"1.0.0","scripts":{"postinstall":"node -e \"require(`fs`).writeFileSync(`ran`,``)\""}}' > tgzsrc/package.json
(cd tgzsrc && npm pack && mv tgzdep-1.0.0.tgz ..)
cd proj && echo '{"name":"proj","version":"1.0.0"}' > package.json
npm install ../dirdep ../tgzdep-1.0.0.tgz
npm install-scripts approve --all
cat package.json # allowScripts has an absolute file:<...>/tgzdep-1.0.0.tgz key
# simulate a teammate's clone: copy the project somewhere else
cd .. && mkdir ../moved && cp -r proj dirdep tgzdep-1.0.0.tgz ../moved/
cd ../moved/proj && rm -rf node_modules && npm install
# -> tgzdep's postinstall is blocked again; dirdep's runs
Environment
- npm: 12.2.3 (
latestbranch) - Node.js: 24.20.0
- OS Name: Windows 11 (the absolute path is
file:C:\\...; on POSIX I'd expectfile:/home/...with the same effect, but I've only tested Windows) - Related: draft PR #9794 changes how these keys are written and fixes this in my test.
- 主要语言
- 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 天内回复