npm v12 の今後の破壊的変更点について
npm v12 はセキュリティ強化のため、スクリプト実行や Git/リモート依存関係の解決を明示的な許可制へ変更する重大な破壊的変更を導入し、開発者のデプロイプロセスに直結する影響を与える。
キーポイント
スクリプト実行のデフォルト無効化
npm install で依存パッケージの preinstall/install/postinstall スクリプトが自動的に実行されなくなり、明示的な許可(allow-scripts)が必要になる。
Git 依存関係の制限強化
Git リポジトリからの依存解決がデフォルトで無効化され、--allow-git フラグによる明示的許可がない限りインストールできなくなる。
リモート URL 依存のブロック
HTTPS ターボールなどのリモート URL からの依存解決もデフォルトで無効化され、--allow-remote フラグが必要となる。
移行準備と承認フロー
npm v12 への移行前に npm approve-scripts コマンドを用いて信頼できるスクリプトをホワイトリスト登録し、package.json にコミットする必要がある。
影響分析・編集コメントを表示
影響分析
この変更は、サプライチェーン攻撃のリスクを大幅に低減する一方で、開発者が依存パッケージのスクリプト実行権限を厳格に管理することを強制します。特に大規模なオープンソースエコシステムや CI/CD パイプラインを持つ組織では、移行前のスクリプト承認プロセスと依存関係の見直しが不可欠となり、デプロイの柔軟性よりもセキュリティが優先される新たな基準となるでしょう。
編集コメント
スクリプト実行のデフォルト停止は、昨今のソフトウェアサプライチェーン攻撃への対策として極めて重要な転換点です。開発者は単なるバージョンアップではなく、依存関係のセキュリティ監査を同時に行う必要があります。
次の npm メジャーバージョンである v12 では、npm install にセキュリティ関連のデフォルト変更が導入されます。これらの変更はすべて、現在の npm 11.16.0 以降で警告として利用可能なので、アップグレード前に準備することができます。v12 のリリースは 2026 年 7 月と見込まれています。
各変更は、今日自動的に実行される npm install の動作を、明示的にオプトインする必要がある動作へと転換します:
allowScripts はデフォルトでオフになります:npm install は、プロジェクト内で明示的に許可されない限り、依存関係からの preinstall、install、postinstall スクリプトを実行しなくなります。これにはネイティブな node-gyp ビルド(binding.gyp を持ち、明示的なインストールスクリプトを持たないパッケージも含まれますが、npm がそのために暗黙的な node-gyp リビルドを実行するためブロックされます)も該当します。git、file、link 依存関係からの prepare スクリプトも同様にブロックされます。何がブロックされるかを確認するには、npm approve-scripts --allow-scripts-pending を実行してください。その後、信頼できるパッケージを npm approve-scripts で許可し、残りを npm deny-scripts でブロックします。結果として生成される許可リストは package.json に書き込まれ、コミットする必要があります。インストールルーチンでスクリプトを実行する場合は、npm 11.16.0 以降で警告を確認できます。
--allow-git はデフォルトで none(なし)になります:npm install は、明示的に --allow-git を指定しない限り、Git 依存関係(直接または間接的)を解決しなくなります。これにより、--ignore-scripts を使用していても Git 依存関係の .npmrc が Git 実行ファイルを上書きできるコード実行経路が閉ざされます。この変更は以前に 2026-02-18 に発表されており、npm 11.10.0 以降で利用可能です。
--allow-remote のデフォルト値が none に変更されます:npm install は、--allow-remote 経由で明示的に許可されない限り、https ターバル(直接または転送依存)などのリモート URL から依存関係を解決しなくなります。このフラグは npm 11.15.0 以降で使用可能です。関連する --allow-file および --allow-directory フラグのデフォルト値は v12 では変更されません。
準備方法
npm を 11.16.0 以降にアップグレードし、通常のインストールを実行して警告を確認してください。npm approve-scripts --allow-scripts-pending を実行して、スクリプトを持つパッケージを特定し、信頼できるものを承認し、更新された package.json をコミットします。その後、アップグレードしても実行されるのは承認したスクリプトのみとなり、未承認のものは停止します。詳細は、npm approve-scripts、npm deny-scripts、および allow-scripts 設定(npx およびグローバルインストール用)に関するドキュメントをご覧ください。コミュニティディスカッションでコメントや質問を共有してください。
本記事「Upcoming breaking changes for npm v12」は、最初に The GitHub Blog で公開されました。
原文を表示
Our next npm major version, v12, introduces security-related default changes to npm install. All these changes are available behind warnings in npm today on 11.16.0 or newer, so you can prepare before the upgrade. v12 is estimated to release in July 2026.
Each change turns an npm install behavior that runs automatically today into one you explicitly opt into:
allowScripts defaults to off: npm install will no longer execute preinstall, install, or postinstall scripts from dependencies unless they are explicitly allowed in your project. This includes native node-gyp builds (i.e., a package with a binding.gyp and no explicit install script still gets blocked, because npm runs an implicit node-gyp rebuild for it). prepare scripts from git, file, and link dependencies are blocked the same way. To see what would be blocked, run npm approve-scripts --allow-scripts-pending. Then allow the packages you trust with npm approve-scripts and block the rest with npm deny-scripts. The resulting allowlist is written to package.json and should be committed. If your install routine runs scripts, you can observe warnings in npm 11.16.0+.
--allow-git defaults to none: npm install will no longer resolve Git dependencies (direct or transitive) unless explicitly allowed via --allow-git. This closes a code-execution path where a Git dependency’s .npmrc could override the Git executable, even with --ignore-scripts. This change was previously announced on 2026-02-18 and is available in npm 11.10.0+.
--allow-remote defaults to none: npm install will no longer resolve dependencies from remote URLs, such as https tarballs (direct or transitive), unless explicitly allowed via --allow-remote. This flag is available in npm 11.15.0+. The related --allow-file and --allow-directory flags are not changing their defaults in v12.
How to prepare
Upgrade to npm 11.16.0 or later, run your normal install, and review the warnings. Use npm approve-scripts --allow-scripts-pending to see which packages have scripts, approve the ones you trust, and commit the updated package.json. After that, only the scripts you approved keep running once you upgrade. Anything you leave unapproved will stop. More details are available in our docs at npm approve-scripts, npm deny-scripts, and allow-scripts config (for npx and global installs). Please share your comments and questions in our community discussion.
The post Upcoming breaking changes for npm v12 appeared first on The GitHub Blog.
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み