Bologu

npm malware wave of 2026: why AI-built sites are at risk, and how to protect yours

Updated · by the Bologu team

2026 has been the worst year on record for npm, the JavaScript package registry. Attackers steal the accounts of people who maintain popular packages, then publish new versions with malware inside. Anyone who installs or builds a project during that window pulls the malware in without noticing. AI-built sites are especially exposed: AI installs packages often and rarely pins versions.

What happened

  • April: Unit 42 tracked two waves calling themselves “Shai-Hulud: The Third Coming” and “Mini Shai-Hulud”, successors to the Shai-Hulud worm that spread through npm in late 2025.
  • June–July: at least 32 packages under @redhat-cloud-services were hit, and AsyncAPI’s release pipeline was breached to publish trojanized versions.
  • August (ChainDrop): Microsoft reported more than 400 compromised packages, including keyv, flat-cache and cache-manager, which many projects pull in without their owners ever installing them directly.
  • November 3: Sonatype found 12 malicious releases across 10 hijacked packages that fetch their next stage through a blockchain. Some had not been updated in years.

What the malware does

From Microsoft’s analysis of ChainDrop, the main pattern is:

  • Runs at install time: a preinstall script runs before installation finishes, before any tests or scanners get a chance.
  • Harvests secrets: .env files, environment variables, GitHub, npm and AWS tokens, SSH keys and GitHub Actions secrets, then sends them out.
  • Spreads itself: with an npm token it publishes infected versions of every package that token’s owner maintains.
  • Hides in AI tools: with stolen GitHub access it adds files to a repo’s .claude and .vscode folders, so opening the project in Claude or VS Code can start the malware again.

Why AI-built sites are more at risk

  • AI runs npm install constantly, and many agents install packages without asking.
  • AI-written package.json files often use ^, * or latest, so yesterday’s release is accepted automatically.
  • Many projects have no lockfile, or build with npm install, which can pick up versions newer than the ones you tested.
  • The machine you code on often holds real production keys in .env.

How to protect your project

  1. Commit a lockfile and build with a lockfile-only install: npm ci, pnpm install --frozen-lockfile or yarn install --immutable instead of npm install.
  2. Don’t take brand-new releases: Microsoft recommends npm CLI v12 with the min-release-age setting, so new versions wait a few days before they can be installed. Malicious versions are usually pulled within hours or days.
  3. Stop using * and latest in package.json.
  4. Keep production keys off the machine you code on. Use separate test keys, and give GitHub and npm tokens only the access they need.
  5. Review files in .claude/, .vscode/ and .github/workflows/ whenever a commit appears that you didn’t make.

If you installed an infected version

  1. Treat every machine and CI runner that installed it as compromised, and rotate every key, token and password from a different, clean machine.
  2. Clear the npm, yarn and pnpm caches on developer machines and in CI.
  3. Reinstall from a lockfile that points to safe versions, then rebuild and redeploy everything.
  4. If you maintain packages yourself, check their publish history for versions you didn’t release.

A prompt for your AI

Harden this project against compromised npm packages:
1. Make sure a lockfile (package-lock.json / pnpm-lock.yaml / yarn.lock) is committed.
2. Change every install in CI, Dockerfile and deploy settings to a lockfile-only install
   (npm ci, pnpm install --frozen-lockfile, yarn install --immutable).
3. Replace "*", "latest" and wide ranges in package.json with the versions now in the lockfile.
4. List every dependency that runs an install script (preinstall/install/postinstall)
   and tell me which ones really need it.
5. Check .claude/, .vscode/ and .github/workflows/ for files or changes I did not make.
Do not upgrade any package in this change.

Let Bologu check for you

The GitHub code check warns when there is no lockfile, when the build uses npm install instead of npm ci, when versions are * or latest, and when packages don’t exist or are barely used. It also compares your locked versions with the OSV.dev vulnerability database.

Sources