npm run demo.What a malicious npm package can do on install, and the settings that stop it. View on GitHub
Recorded runs · nothing executes on this serverA fake package, totally-legit-utils, has a postinstall script that collects tokens from the environment. Both sides really run npm install on it (offline, in a temp folder, with fake tokens).
Fix: ignore-scripts=true in .npmrc, then npm rebuild <pkg> only for packages you've reviewed.
A project's node_modules holds a clean package, a nested one with a preinstall, a native addon (binding.gyp), and one piping a script from the internet into a shell. The scanner here is the real scripts/find-install-scripts.js.
Fix: run the scanner in CI and fail the build when a new install script appears; allowlist only what you've reviewed.
The same script tries to read files, write files, and spawn a process. With --permission, every door is closed unless you open it with an --allow-* flag. Tick a grant to open one.
Fix: start services with node --permission and grant only the folders and capabilities they need.