Dev.to Security ๐Ÿ” Cybersecurity ๐Ÿ‘ 0 ๐Ÿ“– 7 min read

npm Supply Chain Attacks: How to Protect Your App in 2026

Originally published at muhammadmoiz.dev. An npm supply chain attack is when malicious code gets into your app through a package you install, usually because an attacker took over a real maintainer's account or publishe

npm Supply Chain Attacks: How to Protect Your App in 2026

Originally published at muhammadmoiz.dev.

An npm supply chain attack is when malicious code gets into your app through a package you install, usually because an attacker took over a real maintainer's account or published a lookalike package. You protect yourself by making installs reproducible, delaying brand-new package versions, blocking install scripts you haven't reviewed, and keeping secrets away from build machines. None of these steps needs a new tool or budget, and most take an afternoon.

This guide explains what changed in 2026, walks through two recent incidents, and gives you a setup you can copy for npm and pnpm.

What is an npm supply chain attack?

Every JavaScript app depends on hundreds of packages written by strangers. Your project might list 40 dependencies in package.json, but each of those pulls in its own, and the final node_modules folder often holds well over a thousand packages. If any one of them ships a bad version, that code runs with the same access as your app or your build server.

Attackers get malicious code into that tree in a few ways:

  • Account takeover. They steal a maintainer's npm token or GitHub credentials and publish a new version of a popular, trusted package.
  • Typosquatting and slopsquatting. They publish a package with a name close to a real one, or a name an AI coding assistant tends to invent, and wait for someone to install it.
  • Dependency confusion. They publish a public package with the same name as a company's private internal package, hoping the build pulls the public one.

The first route is the dangerous one, because the package name is real, the version number looks normal, and your usual npm install happily accepts it.

Two 2026 incidents worth understanding

The keyv and cacheable worm (August 2026)

Datadog Security Labs documented an attack that started on August 4, 2026. Malicious versions of keyv, cacheable, flat-cache, cache-manager and other caching libraries were published, and Datadog says hundreds of packages were hit in total, some with very high weekly download counts.

What made it nasty was the payload. Each bad version had a preinstall script, so the malware ran the moment someone installed it, before any of your code executed. It then hunted for secrets: environment variables, SSH keys, GitHub tokens, and credentials for AWS, Kubernetes and HashiCorp Vault. On GitHub Actions runners it went after pipeline secrets too. Any npm tokens it found were used to publish infected versions of other packages, which is how it spread like a worm.

Hijacked packages with an Ethereum "dead drop" (November 2026)

On November 4, 2026, Sonatype reported 12 malicious releases across 10 hijacked npm packages, mostly in the @adminide-stack scope plus a few others such as cdeops and server-hemera-mongo. These versions had no install script at all. The malicious loader ran when the app imported the package or started up.

Instead of contacting a fixed server, the loader read a transaction from a hard-coded Ethereum wallet to work out which IP address to download its next stage from. That means the operator can point it at a new server just by sending a new transaction, and blocking one IP address doesn't stop it. The downloaded JavaScript runs inside your process and in a detached Node process that keeps running after your app exits.

Laptop screen showing JavaScript source code in a dark editor
Photo: Arnold Francisca on Unsplash

What these two attacks teach us

Put side by side, they cover both ends of the problem:

keyv / cacheable worm Ethereum dead-drop packages
When it ran During install (preinstall script) When the package was imported
Stopped by blocking install scripts? Yes No
Main goal Steal secrets and spread Remote code execution
Stopped by a release-age delay? Likely, if the bad versions were pulled before your delay ended Likely, for the same reason

No single setting covers everything. You need a few layers.

How do you protect your app from npm supply chain attacks?

Here is the setup I recommend for any Node.js, React or Next.js project, in rough order of value.

1. Commit your lockfile and use clean installs in CI

Your lockfile records the exact version of every package in the tree. Commit it, and in CI use npm ci instead of npm install. According to the npm docs, npm ci stops with an error if the lockfile and package.json disagree, and it never rewrites either file. That means a build can't quietly pick up a new version that nobody reviewed.

For pnpm, the equivalent is pnpm install --frozen-lockfile.

2. Wait a few days before installing brand-new versions

Most hijacked versions are spotted and removed within hours or days. If your tools refuse to install anything published in the last few days, you dodge most of these attacks without doing anything else.

npm's config docs list a min-release-age option measured in days. Add it to the project's .npmrc:

# .npmrc in the project root
min-release-age=3

pnpm has minimumReleaseAge, measured in minutes. Its current docs show a default of 1440 (one day), and you can raise it in pnpm-workspace.yaml:

# pnpm-workspace.yaml
minimumReleaseAge: 4320 # three days, in minutes
minimumReleaseAgeExclude:
  - "@your-company/*" # your own internal packages

If npm config get min-release-age doesn't recognise the setting, upgrade npm first. The trade-off is real: when a genuine security patch ships, you either wait or add a temporary exception for that package.

3. Don't run install scripts you haven't reviewed

The keyv worm needed a preinstall script to do its damage. Most packages don't need one at all.

With npm, set ignore-scripts=true in .npmrc or run npm ci --ignore-scripts in CI. The npm docs note that explicit commands like npm test still run, but lifecycle hooks are skipped. A few packages (image tools like sharp, some native modules) genuinely need a build step, so test your build after switching.

pnpm makes this easier. It blocks dependency build scripts unless you allow them, and you approve the ones you trust by name:

# pnpm-workspace.yaml
allowBuilds:
  sharp: true
  esbuild: true
strictDepBuilds: true # fail the install if an unreviewed package wants to run scripts

pnpm also has a trustPolicy setting. Setting it to no-downgrade makes pnpm fail when a package's trust level drops compared with earlier releases, for example a package that used to be published from CI with provenance suddenly arriving without it. It's off by default.

4. Keep secrets away from install time

Assume that one day a bad package will run on a developer laptop or a CI runner. Limit what it can reach:

  • Install dependencies in a CI step that has no deploy keys or cloud credentials. Add secrets only to the later steps that need them.
  • Use short-lived, narrowly scoped tokens instead of long-lived personal access tokens.
  • Don't keep production .env files on developer machines.
  • Turn on two-factor authentication for your npm and GitHub accounts.

5. If you publish packages, drop long-lived tokens

If your team publishes to npm, set up trusted publishing. The npm docs describe it as publishing from GitHub Actions, GitLab CI/CD or CircleCI using short-lived OIDC credentials instead of a stored token, and it needs npm CLI 11.5.1 or newer. Once it works, the docs recommend switching the package to "Require two-factor authentication and disallow tokens", which removes the stealable token the keyv worm relied on.

6. Watch for advisories

Keep npm audit (or GitHub's Dependabot alerts) running, and pay attention when a package you use makes the news. Audit tools report known problems, not new ones, which is why steps 1 to 4 matter more.

If you installed an affected version: Don't just delete it and move on. Work out whether the code actually ran, then rotate every credential that machine or pipeline could reach: npm and GitHub tokens, cloud keys and CI secrets. Both Sonatype and Datadog published indicators of compromise you can search your logs for.

A quick checklist

  • Lockfile committed, CI uses npm ci or pnpm install --frozen-lockfile
  • Release-age delay set (min-release-age or minimumReleaseAge)
  • Install scripts blocked by default, with an allowlist for the few that need them
  • Dependency install step in CI has no production secrets
  • 2FA on npm and GitHub, no long-lived publish tokens
  • Dependabot or npm audit alerts going to someone who reads them
  • Unused dependencies removed (fewer packages, fewer chances)

What this means for business and app owners

If you run a SaaS, store or internal tool, you probably don't read your package.json, and you shouldn't have to. But you should know whether someone has done the steps above, because the cost of skipping them isn't a broken page. It's leaked customer data or cloud keys used to run up a bill in your name.

This matters even more for apps built with AI tools like Lovable, Bolt or Replit. Those projects often pull in a lot of packages quickly, AI assistants sometimes suggest package names that don't exist (which is exactly what slopsquatters exploit), and nobody has reviewed the build pipeline. I covered the other common gaps in vibe coding security.

Ask your developer three questions: Do we use clean installs from a committed lockfile? Do we block new and unreviewed packages? Could a bad package reach our production secrets? If you don't get confident answers, a production audit is a good place to start. If your backend is Node.js and needs a proper hardening pass, that's part of my Node.js backend work.

Sources

I'm Muhammad Moiz, a full-stack developer who builds web apps, SaaS and POS systems, and takes AI-built apps (Lovable, Bolt, Replit) to production. Get in touch.

๐Ÿ“ฐ Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.