[BUG] allowScripts doesn't stop a git dependency's prepare script
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 56/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, node.js
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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)
- Ngôn ngữ chính
- JavaScript
- Star
- 10.3k
- Fork
- 5k
- Merge trung bình
- 4 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 26
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của npm/cli
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endingsCó thể đã có người làm @saruk-vedant đã nhận 7 ngày trước. Đang mởBug Needs Triage Triage Requested
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[BUG] npm pkg delete removes the first array item for a nonexistent propertyCó thể đã có người làm @drawliin đã nhận 42 ngày trước. Đang mởcmd:delete Priority 3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 2 ngày
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings loggedCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởEngineering Priority 1
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 2 ngày
-
`npm audit signatures` does not report how many packages it skipped for want of registry keysCó thể đã có người làm @greenlincoln05 đã nhận 63 ngày trước. Đang mởPriority 3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 2 ngày
Issue tương tự
-
docs: add SECURITY.md vulnerability reporting policyCó thể đã có người làm @AK-Lmn đã nhận hôm nay. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
flisk-sh/linux2wasm#12 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
possible bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Mintplex-Labs/anything-llm#7388 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 60/100
Maintainer thường phản hồi trong vòng 1 ngày
-
v6: Minified bootstrap.min.css is missing header infoCó thể đã có người làm @lazerg đã nhận hôm nay. Đang mởbug build confirmed has-pr v6
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[workshop-sync] workshop/side-quest-26-01-forecast-costs.md: forecast default history window is inaccurateCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởdocumentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
githubnext/gh-aw-workshop#6332 ·
Maintainer thường phản hồi trong vòng 1 ngày