Reading — step 1 of 5
Read
~1 min readLockfiles & Production
Lifecycle Scripts
Most package managers run scripts at install time:
preinstall— before installing this package's depsinstall— typical native-extension build (e.g. node-sass compiles)postinstall— after install (e.g. set up CLI symlinks)
{
"scripts": {
"preinstall": "echo Hi",
"postinstall": "node scripts/setup.js"
}
}
Scripts are a MAJOR security surface:
- They run shell commands as your user
- They run during dependency installation, not just YOUR code
- A malicious or compromised dep can do anything your shell can
Real attacks:
- eslint-scope (npm 2018): postinstall stole npm credentials
- rc (npm 2018): same, exfiltrated env vars
Defenses:
--ignore-scriptsflag — don't run any (much safer; some packages won't work)- Sandboxing (yarn 2's strict mode, deno's permissions) — scripts can't access your full system
- Vendored dependencies (Go modules' default approach) — no script runtime
pnpm enables --ignore-scripts by default for transitive deps; only your direct deps get scripts. A reasonable middle ground.
For this lesson: model script execution + ordering.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…