[BUG] allowScripts doesn't stop a git dependency's prepare script

Đang mở
#10,305 3 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@farismuhammad17 đang làm issue này rồi.

Từ ngày 24/11/2026.

  • #10342 của @farismuhammad17 — đang mở

Đá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
Lĩnh vực
backend, security

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ả

Bug feat:allow-scripts Priority 1
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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của npm/cli

Tất cả issue của npm/cli

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.