Skip to content
DevPlainly
Security

npm 12 Disables Install Scripts: What Breaks and How to Fix

npm 12 stops dependency install scripts by default. We ran one package on npm 10 and 12, then approved it with allowScripts. Here is what changes.

Published
Reading time
6 min read
Contents
  1. What an install script is, and why attackers use it
  2. What npm 12 changes
  3. Try it yourself: npm 10 against npm 12
  4. Approve the scripts you trust
  5. Protect your CI
  6. What this doesn't protect you from
  7. A checklist for your project
  8. FAQ
  9. Does npm 12 still run postinstall scripts?
  10. How do I allow sharp, esbuild or bcrypt?
  11. Is ignore-scripts=true the same as allowScripts?
  12. Does npm audit catch malicious install scripts?
  13. Further reading

npm 12 changes one default that many projects depend on without knowing it. When a package you install has a postinstall script, npm 10 runs it automatically. npm 12 doesn't. It skips the script, prints a warning and keeps going. That's good for security, and it can break things that used to work.

This guide shows the difference with a harmless test package, explains why install scripts are a common attack path, and shows how to approve only the scripts you trust.

Nil's note

I've always built my own npm projects, and I've never had a problem with them.

What an install script is, and why attackers use it

A package can declare scripts in its package.json. The ones that run during installation are preinstall, install and postinstall. Packages use them legitimately: to compile a native module such as sharp, esbuild or bcrypt, or to download a binary.

The same hook also runs code on your machine before you've read a line of the package. That's why supply-chain attacks on npm often hide their payload in an install script: a compromised package doesn't need you to import or run it. Just installing it is enough.

What npm 12 changes

npm 12 turns the protection on by default. According to the GitHub changelog for the release, published July 8, 2026, these are off unless you allow them:

  • Install scripts (preinstall, install, postinstall), including the automatic node-gyp builds.
  • Git dependencies, controlled by allow-git.
  • Remote URL dependencies, controlled by allow-remote.

npm 12 can read the allow list from package.json, under allowScripts. Its install step is npm install-scripts approve <package>.

Try it yourself: npm 10 against npm 12

We made a test package whose only job is to write a file when it's installed. Its package.json runs this script on install:

{
  "name": "harmless-demo",
  "version": "1.0.0",
  "scripts": {
    "postinstall": "node -e \"require('fs').writeFileSync(process.env.DEMO_MARK,'postinstall ran\\n')\""
  }
}

Pack it, then install it into a small project with npm 10.9.4:

npm pack
cd app
DEMO_MARK=$PWD/mark10.txt npm install ../pkg/harmless-demo-1.0.0.tgz
cat mark10.txt
added 1 package, and audited 2 packages in 626ms

found 0 vulnerabilities
postinstall ran

The script ran, and the file exists. Now the same install with npm 12.2.2, in a clean project:

DEMO_MARK=$PWD/mark12.txt ../n12/node_modules/.bin/npm install ../pkg/harmless-demo-1.0.0.tgz
ls mark12.txt
added 1 package in 382ms
npm warn install-scripts 1 package had install scripts blocked because they are not covered by allowScripts:
npm warn install-scripts   harmless-demo@1.0.0 (postinstall: node -e "require('fs').writeFileSync(process.env.DEMO_MARK,'postinstall ran\n')")
npm warn install-scripts
npm warn install-scripts Run `npm install-scripts ls` to review, or `npm install-scripts approve <pkg>` to allow.
ls: cannot access 'mark12.txt': No such file or directory

The install didn't fail. The package is there, but its script didn't run, and npm told us why. The exit code was 0, so a build that only checks whether npm install succeeded would pass, and then the app would fail later when it tried to use the missing compiled code. That's the first thing to watch for.

Approve the scripts you trust

To review what npm skipped:

npm install-scripts ls
1 package has install scripts blocked because they are not covered by allowScripts:
  harmless-demo@1.0.0 (postinstall: node -e "require('fs').writeFileSync(process.env.DEMO_MARK,'postinstall ran\n')")

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

If you trust the package, approve it:

npm install-scripts approve harmless-demo

npm writes the decision into package.json:

{
  "name": "app",
  "version": "1.0.0",
  "dependencies": {
    "harmless-demo": "file:../pkg/harmless-demo-1.0.0.tgz"
  },
  "allowScripts": {
    "file:../pkg/harmless-demo-1.0.0.tgz": true
  }
}

Now reinstall from scratch. The script runs again:

rm -rf node_modules && DEMO_MARK=$PWD/mark12b.txt ../n12/node_modules/.bin/npm install
cat mark12b.txt
added 1 package in 473ms
postinstall ran

That's the workflow: npm skips the script, you read what it does, and you approve it in a file you commit. Keep the approvals in version control, so a teammate who adds a new package sees the change in review, the same way they'd see a new dependency.

The key in allowScripts is the package location. In our test it's a local file, so it's a path. For a package from the registry, npm keys the entry by name and version. We haven't tested that case in this guide, so check the key npm writes in your own project before you rely on it.

Protect your CI

On a developer laptop, a warning is easy to miss. In CI, you want the build to fail when a script is blocked, so a new dependency can't break a deploy without anyone noticing. npm 12 has a --strict-allow-scripts flag for this. We haven't verified its exact behavior on npm 12.2.2 yet, so test it in your own pipeline before you depend on it.

What this doesn't protect you from

Blocking install scripts closes one door. It doesn't make a package safe:

  • Code that runs when you require or start the package isn't affected. A malicious package can still run code when your app loads it.
  • A stolen token is still stolen. If a secret lives in your environment during a build, anything that runs during that build can read it. Keep secrets in a .env file kept out of Git, and don't expose them to build steps that don't need them.
  • A brand-new malicious version of a package you already trust isn't blocked by this change. Waiting before you install a version that was just published helps, and npm has a min-release-age setting for it that we haven't tested yet.

A checklist for your project

  1. Upgrade with npm install -g npm@12 only after you've tested your build on it.
  2. Run npm install and read every install-scripts warning.
  3. For each warning, check what the script does, then approve it or deny it.
  4. Commit package.json, so the approvals are reviewed like any other change.
  5. Make CI fail on blocked scripts.

FAQ

Does npm 12 still run postinstall scripts?

Not by default. npm 12 skips install scripts unless the package is in allowScripts. You can approve them one by one with npm install-scripts approve.

How do I allow sharp, esbuild or bcrypt?

Run npm install, read the warning, and approve the package with npm install-scripts approve <name>. The approval goes into allowScripts in package.json. Check that the build still works afterwards.

Is ignore-scripts=true the same as allowScripts?

No. ignore-scripts=true turns off every install script, including the ones you trust. allowScripts lets you turn on the ones you've reviewed and leave the rest off.

Does npm audit catch malicious install scripts?

Not reliably. npm audit checks known vulnerabilities in advisories. A package that was published recently, or that was compromised and not yet reported, may not appear there. Reviewing approvals is the part you control.

Further reading

Written by Nil Martinez

Developer · DAM & DAW student

Developer studying multiplatform (DAM) and web (DAW) application development. I work every day with TypeScript, Angular, React, Java, Python, FastAPI, MySQL and Docker on Kubuntu, and I write about the tools I actually use.

How I test and write each guideGitHub

Keep reading