Security How-to

npm 12 blocks install scripts by default, but the install still exits 0: a strict CI gate for dependencies your agent adds

The new allowScripts policy turns a dependency's postinstall into something a human has to approve. Real output from npm 12.2.3, the one flag that makes it fail CI, and a 15-line check for approvals that sneak into a diff.

A row of sealed iron hatches in a stone wall, the middle one open a crack with teal light escaping

An agent adds sharp to resize avatars. The install finishes, the tests pass, the diff is a package.json line and a lockfile. Nobody sees that sharp ships an install script, because on every npm before 12 that script just ran, with the developer’s permissions, on the laptop and then again in CI.

npm 12 changed the default. Per the 12.0.0 release notes (published 8 July 2026), dependency lifecycle scripts are now blocked unless the root package.json allows them in an allowScripts policy. That’s a real improvement for agent-driven work, where dependencies get added by something that doesn’t read install scripts. But there’s a catch that matters for CI: a blocked script is a warning, and the install exits 0. Left alone, the new default is a message in a log that nobody reads.

This piece shows the exact behaviour on npm 12.2.3 (the latest release as of 18 November 2026), the single flag that turns the warning into a failed build, and a small script that catches the other way the policy gets defeated: the agent approving the scripts itself. None of it depends on which coding agent adds the package. Anything that can run a shell and read a diff works with it.

What a blocked install looks like

Start with an empty project and install a package that has a postinstall. This uses esbuild 0.25.0, which has one:

npm init -y
npm install esbuild@0.25.0

On npm 10.9.9 the script runs silently, as it always did. On npm 12.2.3 the output ends like this:

added 2 packages, and audited 3 packages in 1s

found 0 vulnerabilities
npm warn install-scripts 1 package had install scripts blocked because they are not covered by allowScripts:
npm warn install-scripts   esbuild@0.25.0 (postinstall: node install.js)
npm warn install-scripts
npm warn install-scripts Run `npm install-scripts ls` to review, or `npm install-scripts approve <pkg>` to allow.

The package installed. Its script didn’t run. And echo $? after the command prints 0, so a CI job that runs npm ci goes green with the same warning in its log.

To prove the older behaviour is real, a local package with a postinstall that writes a marker file into the project directory leaves postinstall-ran.txt behind on npm 10.9.9 and leaves nothing behind on 12.2.3. That marker file is the whole supply-chain problem in one line: code from a package, running at install time, before anyone has imported it.

Reviewing and approving, on purpose

The review command lists what’s pending, with the script that would run:

npm install-scripts ls
1 package has install scripts blocked because they are not covered by allowScripts:
  esbuild@0.25.0 (postinstall: node install.js)

Run `npm install-scripts approve <pkg>` to allow, or `npm install-scripts deny <pkg>` to deny.

The npm docs also describe npm approve-scripts with the same options (--all, --allow-scripts-pending, --no-allow-scripts-pin). Both spellings exist in 12.2.3. npm approve-scripts --allow-scripts-pending prints the same listing and, like ls, exits 0 when something is pending, so don’t use it as a check.

Approving writes into package.json:

npm install-scripts approve esbuild
node -e "console.log(JSON.stringify(require('./package.json').allowScripts))"
Approved esbuild:
  added esbuild@0.25.0
{"esbuild@0.25.0":true}

The entry is pinned to the exact version by default. That has a useful consequence. Move to 0.25.1 and the approval no longer applies:

npm install esbuild@0.25.1
npm warn install-scripts 1 package had install scripts blocked because they are not covered by allowScripts:
npm warn install-scripts   esbuild@0.25.1 (postinstall: node install.js)

An approval is a statement about a version you looked at, not a standing licence for whatever the maintainer publishes next. Pass --no-allow-scripts-pin to approve by name only. Don’t, unless you have a reason; the pin is what makes a compromised patch release show up as a new warning instead of a quiet success.

Denying is the other half. npm install-scripts deny esbuild writes "esbuild": false (name-only, every version), and a denied package is skipped silently from then on. Per the docs, an existing false entry is never overridden. Approving a denied package prints esbuild is denied; remove the entry from allowScripts to approve esbuild. and changes nothing, so reversing a denial is a deliberate edit to the file.

One caveat from the local-package runs. A package installed from a tarball or a path is keyed by its file: location, not by name and version, so the pin doesn’t mean the same thing there. The registry examples above are the ones to rely on.

One flag makes it fail the build

npm 12.2.3 ships a config called strict-allow-scripts, default false. The config docs say it turns the policy “from a warning into a hard error” for any dependency with install scripts that’s neither approved nor denied. Run it against the unreviewed project:

rm -rf node_modules
npm ci --strict-allow-scripts
npm error code ESTRICTALLOWSCRIPTS
npm error --strict-allow-scripts: 1 package(s) have install scripts not covered by allowScripts:
npm error   fast-resize@2.3.1 (postinstall: node setup.js)
npm error Approve them with `npm install-scripts approve`, deny them with `npm install-scripts deny`, or bypass this check with `--dangerously-allow-all-scripts`.

The exit code is 1. With the entry approved or denied in package.json, the same command installs and exits 0. Two details from the docs: the flag only complains about unreviewed packages (a denied one stays silent), and --ignore-scripts or --dangerously-allow-all-scripts override it. Search your pipelines and your agent’s instructions for the second flag. It’s the new --no-verify.

To make it permanent, put it in the project’s .npmrc so every install, the agent’s included, inherits it:

strict-allow-scripts=true

Now an agent that runs npm install sharp gets a failed command and the error text above, in its own transcript, at the moment it matters. A failing command is something an agent reacts to. A warning on a successful command is something it summarises as “installed successfully”.

The gap the flag doesn’t close

Strict mode checks that every script has a decision. It doesn’t care who made the decision. An agent that hits ESTRICTALLOWSCRIPTS has a one-line way out, npm install-scripts approve --all, and a goal-driven agent will find it. The install then passes, package.json gains an allowScripts entry, and the policy is satisfied on paper.

So the second control is reviewing the approvals as a diff. The only thing that has to be true is that a new true entry never reaches the main branch without a human having seen it. This check compares the branch’s allowScripts with the base branch’s and fails on any newly approved entry:

#!/usr/bin/env python3
"""Fail when a branch adds an install-script approval that the base branch didn't have."""
import json
import subprocess
import sys

base_ref = sys.argv[1] if len(sys.argv) > 1 else "origin/main"


def allow_scripts(text):
    return json.loads(text).get("allowScripts", {}) or {}


base = allow_scripts(subprocess.check_output(["git", "show", f"{base_ref}:package.json"], text=True))
head = allow_scripts(open("package.json", encoding="utf-8").read())

added = {k: v for k, v in head.items() if v is True and base.get(k) is not True}
for key in sorted(added):
    print(f"NEW APPROVAL: {key} may now run install scripts")
sys.exit(1 if added else 0)

Here it is against a repo where the base branch denies esbuild. After the agent installs sharp and runs npm install-scripts approve --all:

NEW APPROVAL: sharp@0.34.5 may now run install scripts

Exit code 1. With no change to allowScripts it prints nothing and exits 0. Note that approve --all skipped the denied esbuild entry, as the docs say it will.

Run it in the pull request pipeline. A human clears it the ordinary way, by reviewing a diff line such as "sharp@0.34.5": true and looking the package up, which takes a couple of minutes. Pair it with a CODEOWNERS entry for package.json if the team already uses them. The check doesn’t decide whether sharp is safe. It makes sure a person decided.

Put it in the agent’s instructions too

The CI checks are the control. The instructions are the courtesy that saves the agent a failed round trip. In whichever file your agent reads (CLAUDE.md, AGENTS.md, a Cursor rule, a Copilot instructions file), something like:

Dependencies: npm 12 blocks install scripts. Never run `npm install-scripts approve`,
never pass `--dangerously-allow-all-scripts` or `--ignore-scripts` to get an install
through, and never edit `allowScripts` by hand. If an install fails with
ESTRICTALLOWSCRIPTS, stop and report the package, the script text from the error, and
why the package is needed. A human approves.

Then check that the agent complied the only way that counts: the pipeline’s approval check, not the agent’s word.

What goes wrong

  • Native-module packages. Packages that compile or download a binary in install (sharp, esbuild and canvas are the familiar names) will be blocked, and some of them work without the script while others fail at import time. After approving, run npm rebuild to execute the newly approved scripts, as the release notes say. Test the import before you merge.
  • prepare on non-registry sources. The config docs list prepare among the scripts that are gated for non-registry dependencies, so git dependencies are caught too. npm 12’s release notes also say allow-git and allow-remote now default to “none”.
  • Node version. npm 12 supports specific ranges of Node 22.x and 24.x and 26 or later per the release notes. A pipeline on an older Node can’t adopt it yet.
  • Unknown flags now throw. Per the same notes, unknown and abbreviated CLI flags are errors in npm 12. A mistyped --strict-allow-script fails instead of quietly doing nothing, which is what you want here.
  • This is not a vulnerability scanner. It stops install-time execution. A package can still do harm when it’s imported at runtime, which is why a release-age floor (see the npm release-age post ) and lockfile review stay in the pipeline.
  • Global installs and npx use the allow-scripts config, not the project policy. Passing --allow-scripts to a project-scoped install, ci, update or rebuild is an error.

Don’t bother if the repo has no dependencies with install scripts and no agent adding packages. A clean npm install-scripts ls is already the answer, and the strict flag costs nothing to leave on.

The first 15 minutes

Upgrade npm in a branch (npm install -g npm@12) and run npm install-scripts ls in a real project. That list is your current exposure: every package whose script used to run unseen. Approve the ones you recognise, deny the ones you don’t need, commit the allowScripts block, add strict-allow-scripts=true to .npmrc, and add the diff check above to the pull request workflow.