Skip to content

NPM 12、スクリプトポカリプスに終止符を打つ

長年、たった一度の`npm install`があなたのマシンにサプライチェーン攻撃を解き放つ可能性がありました。NPM 12は、デフォルトでスクリプトの自動実行を停止することにより、ついにその扉を閉ざします。

Theo Brandt
Hero image for: NPM 12、スクリプトポカリプスに終止符を打つ

要約 / ポイント

長年、たった一度の`npm install`があなたのマシンにサプライチェーン攻撃を解き放つ可能性がありました。NPM 12は、デフォルトでスクリプトの自動実行を停止することにより、ついにその扉を閉ざします。

コード実行の無秩序な状態が終焉を迎える

`npm 12`は、パッケージインストールの無法地帯にようやく終止符を打ち、`npm install`が静かなコード実行の無秩序な状態を兼ねていた危険な時代を終わらせます。長年、`pre-install`および`post-install`スクリプトは、`install`スクリプトと共に、すべての依存関係に対して自動的に実行され、日常的なタスクを陰湿なサプライチェーン攻撃の主要な媒介に変えていました。このデフォルトの動作は、単純なパッケージの取得を高リスクな賭けに変えていました。

JavaScriptエコシステム全体は、暗黙の信頼モデルに支えられており、明示的なユーザーの同意なしに、任意のパッケージがインストール中に任意のコードを実行することを許していました。攻撃者はこの盲点を巧みに悪用しました。例えば、自己増殖型のShai-Huludワームは、数百のパッケージを侵害して認証情報を抜き取り、自律的に拡散しました。一方、2026年5月の「Mini Shai-Hulud」亜種は、GitHub Actionsを悪用して`TanStack`のような著名なプロジェクトを標的にしました。

コミュニティはこの重大な脆弱性について長年議論してきました。喫緊のセキュリティニーズと、広大でスクリプトに依存するエコシステム全体で後方互換性を維持するという途方もない課題の間で板挟みになっていました。今、`npm 12`はこのゴルディオンの結び目を断ち切ります。デフォルトでスクリプトの自動実行を無効にし、`npm approve-scripts`を介した明示的な承認フローを強制します。この長らく待ち望まれた暗黙の信頼から明示的な許可リストへの移行は、ついにセキュリティを優先し、わずかに不便になるかもしれませんが、より安全な未来をもたらします。

あなたの新しい門番: `npm approve-scripts`

バージョン12の`npm install`は、依存関係からの任意のコードを盲目的に実行することはもうありません。`pre-install`、`install`、`post-install`スクリプトがデフォルトで実行される時代は決定的に終わり、Shai-Huludや最近のTanStack侵害のようなサプライチェーン攻撃の重要な媒介を終焉させます。この全面的なブロックは、Git、ファイル、またはリンクの依存関係から供給される不可欠なネイティブ`node-gyp`ビルドや`prepare`スクリプトにまで及び、予期せぬコード実行が始まる前に効果的に無力化します。

あなたの新しい門番、`npm approve-scripts`が登場します。このコマンドは、明示的で監査可能なワークフローを導入し、開発者がすべてのスクリプトをレビューし、本当に信頼するものだけを選択的に有効にすることを可能にします。承認されると、`npm`はこれらの許可を`package.json`ファイル内に直接保存し、インストール中に実行される許可されたコードの透明でバージョン管理された記録を作成します。これにより、以前の危険な自動化は、意図的で情報に基づいた同意に置き換えられます。

これは単なる新しいコマンドではありません。JavaScriptエコシステム全体にとって、深い哲学的転換です。`npm`は、暗黙の信頼(任意の依存関係が何でも実行できるモデル)から、明示的な許可リストのモデルへと決定的に移行します。開発者は、自分のマシンでどのコードが実行されるかについて、絶対的かつきめ細かな制御を取り戻し、`npm install`を潜在的な負債から、意図的で安全な操作へと変革します。スクリプトポカリプスは、弱々しい嘆きではなく、確固たる、監査可能な「ノー」と共に終わります。

さらなる攻撃ベクトルを封鎖する

While `pre-install` and `post-install` scripts were the flashiest vectors for supply chain attacks, shrewd adversaries never put all their eggs in one basket. They also leveraged less obvious pathways, like direct Git dependencies and remote URL tarballs, to sneak malicious code into unsuspecting projects. Attackers famously exploited these methods in incidents such as the Mini Shai-Hulud variant that targeted packages under the TanStack namespace, often injecting malicious `.npmrc` files via these indirect routes.

npm 12 slams these secondary doors shut with a simple, explicit mandate. Developers must now use `--allow-git` to resolve Git-based dependencies and `--allow-remote` when installing packages from URL-based tarballs. This isn't just an inconvenience; it's a critical friction point designed to force conscious decisions, eliminating implicit trust for external sources and significantly narrowing the attack surface.

No one can claim ignorance when npm 12 rolls out in July; warnings for these breaking changes have been active since npm v11.16.0+. This grace period offers ample opportunity for teams to audit their build pipelines and update dependency declarations, avoiding sudden disruptions. For more detail on the upcoming shifts, consult the Upcoming breaking changes for npm v12 - GitHub Changelog.

A Necessary Step, But Is It Enough?

Finally, npm acknowledges reality. The script execution free-for-all, a primary vector for supply chain attacks, is ending with npm 12 after years of widespread exploitation. This long-overdue shift to explicit script approval, finally catching up to more security-conscious alternatives, transforms `npm install` from a naive trust exercise into a guarded operation. It's a necessary evolution, albeit one that arrives in July 2026, years after the first alarms sounded.

Even with these welcome changes, the battle for supply chain integrity continues. Many security experts, myself included, simply advocate for pnpm, which boasts superior defaults like blocking exotic sub-dependencies and delaying new package adoption. pnpm’s proactive stance, which has long championed a more restrictive, secure posture out of the box, offers a compelling alternative for projects demanding immediate, robust protection.

These updates significantly narrow the attack surface, curtailing the `pre-install` and `post-install` script vectors that fueled incidents like Shai-Hulud and the TanStack compromise. The explicit block on Git dependencies and remote tarballs further closes well-worn attack paths. However, attackers are relentlessly adaptive. Expect a pivot to other vulnerabilities, perhaps exploiting malicious `.npmrc` files, CI/CD misconfigurations, or sophisticated social engineering. Developer vigilance, scrutinizing every dependency and build process, remains the ultimate, indispensable firewall in this evolving threat landscape.

Frequently Asked Questions

What is the biggest change in NPM 12?

The most significant change is that `npm install` will no longer automatically run pre-install, install, or post-install scripts for dependencies. Users must now explicitly approve them.

How do I run scripts for trusted dependencies in NPM 12?

You need to use the new `npm approve-scripts` command. This will prompt you to approve scripts from your dependencies, and your selections will be saved to your package.json.

Why is NPM making these security changes now?

これらの変更は、認証情報を盗み、マルウェアを拡散するためにautomatic script executionを悪用した、Shai-Hulud wormのような高度なsupply chain attacksの波への直接的な対応です。

PNPMやYarnのような他のpackage managersはすでにこれほどsecureですか?

はい、PNPMやYarnのような他のpackage managersは、automatic install scriptsのブロックなど、同様のsecurity-by-defaultの動作をかなり前から実装しています。

Found this useful? Share it.

One short daily email of tools worth shipping. No drip funnel.

one email a day · unsubscribe in two clicks · no third-party tracking

🚀もっと見る

AI最前線をキャッチアップ

Stork.AIが厳選したAIツール、エージェント、MCPサーバーをご覧ください。

P.S. 使えるものを作りましたか? Storkに掲載