Install Scripts & allowScripts
A postinstall script in any package of your tree runs arbitrary code on your machine the moment you type npm install, with your user's permissions, before you've imported a single line of it. A few packages need that (native addons, downloaders of platform binaries); most attacks on the npm ecosystem have used it too: a hijacked maintainer account publishes a patch release whose postinstall steals tokens from ~/.npmrc and environment variables. All three package managers now let you decide which dependencies may run install scripts.
| Tool | Default for dependencies' install scripts | Where approvals live |
|---|---|---|
| npm 11.19 | runs them, but warns about any not covered by allowScripts; --strict-allow-scripts makes it an error |
"allowScripts" in package.json |
| pnpm 10 | doesn't run them; prints "Ignored build scripts" | onlyBuiltDependencies in pnpm-workspace.yaml |
| Yarn 4 | doesn't run them (enableScripts: false) |
enableScripts in .yarnrc.yml, dependenciesMeta.<pkg>.built in package.json |
Your own project's scripts are never affected; this is only about scripts inside dependencies.
A package with a postinstall
Each session below first publishes a tiny package, hooky, whose postinstall appends a line to /tmp/hooky.log, so we can see whether it ran.
npm: warn, approve, deny
mkdir -p hooky && cd hooky
echo '{ "name": "hooky", "version": "1.0.0", "scripts": { "postinstall": "echo hooky postinstall ran >> /tmp/hooky.log" } }' > package.json
npm publish > /dev/null 2>&1
mkdir ../app && cd ../app && npm init -y > /dev/null
npm install hooky 2>&1 | grep -v '^