[BUG] npm pack/publish --ignore-scripts runs .npm-extension, and so does installing a git dependency
メンテナーはふだん 2 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, node.js
調査の方向性
Start with pacote's DirFetcher in lib/dir.js and Arborist's extension loading guard in workspaces/arborist/lib/arborist/load-actual.js; trace how ignoreExtension reaches the Arborist created during packing. Then inspect GitFetcher in lib/git.js to see how git dependencies use DirFetcher. Done means the listed pack, publish, and git install commands no longer load .npm-extension when the relevant ignore behavior applies.
索引モデルが 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
npm pack --ignore-scripts and npm publish --ignore-scripts import the package's .npm-extension.cjs/.mjs, and --ignore-extension doesn't stop it either. That undoes what #7211 was after, a publish job that can't be made to run code from the repo it's publishing.
pacote's DirFetcher builds its own Arborist to get the file list, and only gives it { path }:
https://github.com/npm/pacote/blob/453a0adac3592e5f93c8f782fb1b1b320ac95009/lib/dir.js#L79-L80
So ignoreExtension (which ignore-scripts also sets, here) never reaches the only guard in front of ext.load():
https://github.com/npm/cli/blob/60e11343e61316d966c86805d803df5a0eb99230/workspaces/arborist/lib/arborist/load-actual.js#L452-L463
GitFetcher packs every git dependency through the same DirFetcher (git.js#L217-L222), so with allow-git on, npm install --ignore-scripts also imports a git dependency's own .npm-extension, even though .npm-extension is meant to be the root project's file.
Expected Behavior
--ignore-scripts and --ignore-extension stop .npm-extension during pack and publish, and a git dependency's .npm-extension is never loaded. Passing ignoreExtension through to that Arborist would fix pack/publish; for a git dependency's clone it probably wants to be set unconditionally.
Steps To Reproduce
$ mkdir attacker-pkg && cd attacker-pkg
$ echo '{ "name": "attacker-pkg", "version": "1.0.0" }' > package.json
$ cat > .npm-extension.cjs <<'EOF'
require("fs").writeFileSync("/tmp/pwned", "pwned");
console.log("EXTENSION_RAN");
module.exports.transformManifest = (pkg) => pkg;
EOF
$ npm pack --dry-run --ignore-scripts --ignore-extension
EXTENSION_RAN
npm notice Tarball Contents
[..]
attacker-pkg-1.0.0.tgz
$ cat /tmp/pwned
pwned
npm publish --ignore-scripts does the same, with or without --dry-run; the extension runs before anything is sent to the registry. For the git dependency case, commit those two files to a repo, depend on it as git+file:///path/to/repo, and run npm install --ignore-scripts --allow-git=all.
Environment
- npm: 12.2.2
- Node.js: 24.22.1
- OS Name: macOS 26
- npm config: defaults (flags on the command line)
- 主要言語
- JavaScript
- スター
- 10.3k
- フォーク
- 5k
- 平均マージ
- 4日 11時間
- マージ済み PR(30日)
- 26
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン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 日以内に返信
-
documentation
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
githubnext/gh-aw-workshop#6332 ·
メンテナーはふだん 1 日以内に返信