When npm turns against you
Worms, typosquats and hijacked maintainers. How I protect builds from malicious packages.
Worms, typosquats and hijacked maintainers. How I protect builds from malicious packages.

A modern JavaScript project easily has over a thousand dependencies, most of them indirect. Python, Go, Rust and Java projects aren't far behind. Every one of those packages is code written by someone you've never met, running on your laptop and in your CI with access to your secrets.
For years that trust mostly worked. Recently, attackers have shown just how fragile it is.
Without going into every incident, the pattern of the last couple of years is clear:
What these have in common: they don't exploit a bug in your code. They exploit the trust you place in your dependencies.
Installing a package is running a stranger's code with your credentials. We just stopped thinking about it that way.
The basics matter most:
package-lock.json, pnpm-lock.yaml, poetry.lock, uv.lock, go.sum) and install with them strictly: npm ci instead of npm install in CI. That way, a new malicious version can't sneak in during a build.@acme/...) and configure your package manager so internal names can only come from your registry. That prevents dependency confusion, where an attacker publishes a public package with the same name as your internal one.Most malicious package versions are detected and removed within hours or days. So a simple but powerful defence: don't install brand-new versions immediately.
minimumReleaseAge waits a configurable time (for example three days) before proposing an update.You lose a few days on new features. You gain protection against most "publish and hope" attacks.
Many attacks run during installation, through postinstall scripts.
npm config set ignore-scripts true, pnpm's stricter defaults for dependency build scripts) and allow them only for packages that genuinely need them.And a non-tool: question new dependencies. Does this project really need a package for left-padding a string? Every dependency you don't add is one you never have to worry about.
When a compromised package hits your stack:
Strict lockfile installs in CI, a minimum release age for updates, a private proxy registry, and no long-lived publish tokens. Those four measures would have blunted most of the recent attacks.
My take: dependencies are a gift from the open-source world. Accept them gratefully, but check what's inside before you open them in production.
— Desly