Skip to content

What is slopsquatting?

Slopsquatting is registering, with malicious code, a package name that AI assistants tend to invent, so that a developer or agent who installs the suggested name gets the attacker’s package. It works because models recommend plausible package names that do not exist, and anyone can publish an unclaimed name to npm. The defence is to check that a package exists and is the one you meant before it is installed.

By the AI Guard maintainers · Last updated · Applies to v1.4.7

How AI assistants invent package names

Language models suggest packages from patterns in their training data, and sometimes the suggested name has never been published. In a USENIX Security 2025 study of 576,000 code samples, 5.2% of packages suggested by commercial models and 21.7% suggested by open-source models were hallucinated, and the models produced 205,474 unique fake names (Spracklen et al.). The same invented names tend to come back, which makes them worth registering for an attacker.

How the attack works

  1. A model suggests import { helper } from 'react-query-helpers-pro', a name that does not exist.
  2. An attacker who has seen that name suggested registers it on npm, often with code in an install script.
  3. A developer or an agent runs npm install react-query-helpers-pro. The install script runs with their permissions before anyone reviews the code.

Slopsquatting is a variant of typosquatting, where attackers register near-copies of popular names (expresss for express). The difference is where the name comes from: a typo, or a model.

How AI Guard refuses a name that does not exist

AI Guard's package check looks each package up on the public npm registry before it is installed. A name that does not exist is blocked, with the reason:

terminal
$ npx ai-guard verify-deps ai-guard-demo-no-such-package   AI GUARD   Dependencies  ·  1 package  ·  1 blocked  ·  0 warnings   command line          error  ai-guard-demo-no-such-package  "ai-guard-demo-no-such-package" does not exist on npm. AI assistants often invent package names, and anyone can register an invented name later. package-not-found

The command exits with code 1. The same check runs in three places:

  • On the command line: npx ai-guard verify-deps <name>, or npx ai-guard verify-deps to check the dependencies a change adds.
  • Before an agent installs: npx ai-guard init-hooks --check-installs adds a hook that refuses the install in Claude Code, Codex and Cursor.
  • From an MCP client: the ai_guard_check_package tool returns safeToInstall: false.

Earlier, at the import line, the lint rule `no-undeclared-import` flags packages that are not declared in package.json and not installed.

A real campaign: crossenv, 2017

In August 2017 a typosquatting campaign published packages such as crossenv (for cross-env) that sent the installing machine's environment variables, including tokens, to the attacker. npm removed them and left empty security placeholders. AI Guard blocks those placeholders and names the package you probably meant:

terminal
$ npx ai-guard verify-deps crossenv   AI GUARD   Dependencies  ·  1 package  ·  1 blocked  ·  0 warnings   command line          error  crossenv  npm removed the package published as "crossenv" (usually for malware) and replaced it with an empty placeholder. Did you mean "cross-env"? security-holding

Of the 36 names attributed to the campaign, AI Guard blocked 34. The other two are still published by the account that created them in 2017 and were never replaced by npm, so there is no fact to block on: one (openssl.js) gets a warning for being rarely downloaded, and one (opencv.js) passes. AI Guard does not guess. Measured on 12 November 2026; see Results.

Limits

  • Blocking is reserved for facts: the name or version does not exist, npm replaced it with a security placeholder, or a look-alike or install script appears on a package that is new or rarely downloaded. A look-alike that is established gets a warning, not a block. For example, expresss (registered 2016, about 755 downloads a week) installs with a look-alike warning.
  • A new malicious name with no install script and no resemblance to a popular package is reported as new, not blocked.
  • The check only sees installs it is asked about. A release cooldown in your package manager covers every install; see release cooldowns.

Frequently asked questions

Is slopsquatting the same as typosquatting?

They are related. Typosquatting registers near-copies of popular names that people mistype; slopsquatting registers names that AI models invent. AI Guard checks for both: a name that does not exist is blocked, and a look-alike of a popular package is blocked when it is new or rarely downloaded and warned about otherwise.

Does AI Guard send my package names anywhere?

Only to the public npm registry (registry.npmjs.org and api.npmjs.org), and only when you run a package check. Packages served by a private registry are skipped, so internal names are never sent out.

Will it block real packages?

It is designed not to. Across 1,361 real dependencies from 15 large open-source projects and 9 open-source apps, none were blocked. See Results.

Sources