DEV Community

Cover image for AI Invented This npm Package. Someone Registered It. (Slopsquatting)
Muiduzzaman Lipu for Refactorly

Posted on

AI Invented This npm Package. Someone Registered It. (Slopsquatting)

Your AI assistant tells you to install a package. The name sounds right, but the package doesn't exist: the AI made it up. If an attacker registers that name first, the next npm install runs their code.

This attack is called slopsquatting. Here's a real case, a harmless demo of why installing alone is enough, and a 10-second check you can run before installing anything an AI suggests.

All registry numbers below were checked live on November 15, 2026.

Video version:

How slopsquatting works

  1. An AI model suggests a package name that doesn't exist. It sounds plausible, often a mix of two real names.
  2. Different models (and the same model, asked again) often invent the same fake names. Researchers have measured this across several frontier models, so the names are predictable.
  3. An attacker collects those names and publishes real packages under them, with malware inside.
  4. The next developer, or AI agent, who follows the suggestion installs it.

A name-similarity scanner won't help much here. The fake name isn't a typo of a real package; it's a brand-new name.

A real case: react-codeshift

AI-generated agent instructions ("skills") told people to run:

npx react-codeshift …
Enter fullscreen mode Exit fullscreen mode

That command ended up in 200+ files on GitHub. But react-codeshift never existed. The AI had blended two real packages: jscodeshift (Facebook's codemod runner) and react-codemod (the React team's transforms).

On January 14, 2026, Charlie Eriksen, a security researcher at Aikido, noticed and registered the name first, as a harmless placeholder:

$ npm view react-codeshift description
🚫 Placeholder to prevent dependency confusion.
Enter fullscreen mode Exit fullscreen mode

It's still downloaded about 31 times a week (59 times in the last month), most likely by agents and people following those instructions. If an attacker had claimed it first, every one of those installs would have run their code.

Installing is enough: postinstall

You don't even have to import a malicious package. npm runs lifecycle scripts such as postinstall automatically during npm install:

{
  "name": "evil-demo",
  "version": "1.0.1",
  "scripts": {
    "postinstall": "node -e \"require('fs').writeFileSync(require('os').tmpdir()+'/pwned-demo.txt','x')\""
  }
}
Enter fullscreen mode Exit fullscreen mode

I packed that harmless demo package and installed it with npm 11.4:

  • npm install ./evil-demo-1.0.1.tgz: the output showed only added 1 package, but the marker file was created. The script ran silently, with full access to my environment variables (77 of them; a version that printed Object.keys(process.env).length showed it).
  • npm install ./evil-demo-1.0.1.tgz --ignore-scripts: no marker file. The script never ran.

A real attack would read ~/.npmrc, .env files, SSH keys or cloud tokens instead of writing a marker file.

The 10-second check

Before installing something an AI suggests, ask the registry three questions: does it exist, how old is it, and does anyone use it?

// check-pkg.mjs (Node 18+)
const name = process.argv[2];
const reg = "https://registry.npmjs.org/";
const res = await fetch(reg + name);
if (res.status === 404) {
  console.log(`āŒ ${name}: does not exist`); process.exit(1);
}
const { time } = await res.json();
const days = Math.round((Date.now() - new Date(time.created)) / 864e5);
const api = "https://api.npmjs.org/downloads/point/last-week/";
const { downloads } = await (await fetch(api + name)).json();
console.log(`${name}: ${days} days old, ${downloads.toLocaleString("en-US")} downloads/week`);
Enter fullscreen mode Exit fullscreen mode
$ node check-pkg.mjs jscodeshift
jscodeshift: 4254 days old, 7,656,282 downloads/week
$ node check-pkg.mjs react-codeshift
react-codeshift: 305 days old, 31 downloads/week
$ node check-pkg.mjs express-jwt-validator-pro
āŒ express-jwt-validator-pro: does not exist
Enter fullscreen mode Exit fullscreen mode
  • The real package is over 11 years old with 7.6 million downloads a week.
  • The hallucinated one is new and almost unused.
  • A name that doesn't exist at all is the clearest red flag. Don't install it, and don't "fix" it by registering it yourself. Find the real package.

New and unpopular doesn't always mean malicious, but it does mean "look closer": check the repository link, the maintainers and what the code actually does.

For Python, the same check is pip index versions <name> (No matching distribution found means it doesn't exist) or https://pypi.org/pypi/<name>/json (a 404 means the same).

Checklist: before you install what AI suggests

  • āœ… Check that it exists, its age, its weekly downloads and its repository.
  • āœ… Prefer packages you already know, or the ones named in the official docs.
  • āš ļø Be suspicious of names that look like a mashup of two real packages.
  • āœ… Review new dependencies in pull requests, including the ones an agent added.
  • āœ… Don't let AI agents install packages without approval.
  • āœ… Use npm install --ignore-scripts (or ignore-scripts=true in .npmrc) when you can. Some packages genuinely need install scripts, so test that your project still builds.

Has an AI ever suggested a package to you that didn't exist? šŸ‘‡


I post one tested coding tip every day on YouTube at Refactorly. The 30-second version of this one is here.

Top comments (2)

Collapse
 
maxbuildsdev profile image
Max Kaya •

The npm view check is good but it only tells you the name is taken — it doesn't tell you who took it or when, which is exactly the signal that distinguishes a placeholder from a package someone registered last week to catch AI traffic. npm view <pkg> time.created maintainers repository gets you all three in the same call, no extra round trip.

Worth adding: the risk isn't only postinstall. npm install also runs the prepare script for git dependencies, and if the fake name ever points at a repo, that fires too. The cheap structural fix is pinning ignore-scripts=true in .npmrc for agent-driven work and running npm rebuild on the specific native packages that need it (sharp, better-sqlite3), because a blanket ignore breaks those silently. If you use pnpm, onlyBuiltDependencies in package.json is the cleaner version of the same allow-list.

Did the 31 weekly downloads number move after the post went out? That would be a decent proxy for how many of those agents read dev.to.

Collapse
 
parasraju profile image
Paras •

The react-codeshift story is exactly why I check first now.