← Back to blog

AI Hallucinates 1 in 5 Packages — Slopsquatting Explained

Slopsquatting: How AI hallucinations inject malware into your builds. Learn why LLM-generated code poses a critical supply chain threat to developers.

AI Hallucinates 1 in 5 Packages — Slopsquatting Explained

A developer asks an AI assistant how to solve a problem, gets working code plus an install command, and runs it — the whole exchange takes ninety seconds. If the package name in that command was invented by the model and later registered by an attacker, malicious code just entered the build with full access to credentials, tokens, and the CI pipeline.

That is slopsquatting: a supply chain attack that does not wait for a human to make a mistake. It waits for the AI to make one — predictably, at scale.

What Slopsquatting Is, and How It Differs From Typosquatting

Typosquatting is an old trick: attackers register package names that look like popular ones — requets instead of requests — and bet that a tired developer will mistype an install command. It works, but it depends on individual human error, one typo at a time.

Slopsquatting removes the human from the equation. Large language models sometimes recommend packages that do not exist — plausible-sounding names that fit the naming conventions of npm or PyPI but were never published. Attackers can harvest those hallucinated names, register them on the public registry with malicious code inside, and simply wait. The next time any model suggests that name to any developer anywhere, the trap is already set. The term was coined by Seth Larson, security developer-in-residence at the Python Software Foundation, as documented in The Register's coverage of the research.

An everyday analogy: typosquatting is a knockoff shop with a misspelled sign, hoping you misread it. Slopsquatting is different — your GPS confidently directs you to a restaurant that never existed, and someone who studied the GPS's habits built a stand at exactly that address, with exactly that name on it. You did nothing wrong. You followed directions from a tool you trust.

Typosquatting Slopsquatting
Trigger Human typo AI hallucination
Attacker's bet Someone misspells a real name A model re-invents the same fake name
Scale One mistake at a time Every user of every affected model
Victim's confidence Low — typos feel uncertain High — AI output feels authoritative

That last row is the dangerous part. A developer who mistypes a command may double-check it. A developer who receives a clean, confident answer from an assistant usually does not.

Real Numbers: How Often Models Invent Packages

This is not a theoretical risk. A joint study from the University of Texas at San Antonio, the University of Oklahoma, and Virginia Tech — published on arXiv and accepted at USENIX Security 2025 — tested 16 code-generation models across 576,000 generated code samples. The findings:

  • 19.7% of recommended packages did not exist. Roughly one in five.
  • The samples produced 205,474 unique hallucinated package names — a ready-made target list for anyone willing to register them.
  • Commercial models hallucinated packages about 5.2% of the time; open-source models averaged 21.7%.
  • The critical result: hallucinations repeat. When researchers re-ran the same prompts ten times, 43% of hallucinated names appeared in every single run, and 58% recurred at least once.

That repeatability is what turns a quirk into an attack surface. If hallucinations were random noise, registering fake names would be a lottery. Because models reproduce the same fake names for the same prompts, an attacker can harvest names today and be reasonably confident developers will be told to install them tomorrow.

The attack has already been demonstrated in the wild — responsibly. Security researcher Bar Lanyado noticed that models repeatedly recommended a nonexistent Python package called huggingface-cli. He registered it as a harmless empty package. It was downloaded more than 30,000 times in three months, and Alibaba's open-source GraphTranslator project even included it in its installation instructions. No exploit, no social engineering — just a hallucinated name, registered and waiting.

Why This Matters for Business

Software supply chain attacks are not a niche concern. Sonatype's State of the Software Supply Chain report logged over 512,000 malicious open-source packages in its 2024 edition — a 156% year-over-year increase. Registries are open marketplaces: anyone can put a box on the shelf under any unclaimed name, and the shelf does not check what is inside.

The business exposure compounds through three facts:

Installation is execution. On npm, a package can run scripts the moment it is installed — before a single line of it is ever imported. A malicious dependency does not need to be used to do damage; being installed on a developer laptop or CI runner is enough to exfiltrate environment variables, cloud credentials, and signing keys.

One dependency inherits everything. A build pipeline typically holds deployment keys, registry tokens, and access to production infrastructure. A single poisoned package sits inside that trust boundary. IBM's Cost of a Data Breach research puts the global average breach at $4.88 million in 2024 — and supply chain incidents tend to run longer and cost more because detection is harder.

AI adoption multiplies the entry points. The same assistants that make teams faster also generate install commands that get pasted without review. The related dependency-confusion technique showed how far this class of attack reaches: in 2021, researcher Alex Birsan used lookalike internal package names to penetrate build systems at more than 35 companies, including Apple, Microsoft, and Tesla, collecting over $130,000 in bug bounties for the demonstration. Slopsquatting follows the same trust seam — the registry — with an even cheaper way to guess names: let the AI do it.

The uncomfortable asymmetry: registering a package name costs an attacker nothing and takes minutes. The defense, done properly, costs a team a few hours of setup. Most teams have not spent those hours.

Here Is What We Recommend

Defense against slopsquatting is layered, and the layers are cheap relative to what they protect. Ordered by effort:

1. Treat AI package suggestions as unverified input

The single highest-value habit costs about two minutes per new dependency. Before installing anything an assistant suggests, open its registry page and check three things: how long the package has existed, how many downloads it has, and whether it links to a real repository with real history. A package registered three weeks ago with no repository and a name nobody has heard of is a red flag regardless of how confidently the AI recommended it. This is a team policy, not a tool — write it into the onboarding doc.

2. Lockfiles, enforced

Lockfiles (package-lock.json, poetry.lock, pnpm-lock.yaml) pin exactly which packages and versions a project uses. The key is enforcement: CI should install strictly from the lockfile (npm ci rather than npm install), so a hallucinated package cannot slip into a build without an explicit, reviewable lockfile change. For Python, hash-pinning via pip-tools adds the same guarantee. Setup cost: an afternoon. Effect: every new dependency becomes a visible diff in code review instead of a silent side effect.

3. A minimum-age gate for new packages

Slopsquatted packages are, by definition, freshly registered — the attacker creates them after harvesting hallucinated names. Tools like Renovate and recent versions of pnpm support a minimum release age, refusing packages or versions younger than a threshold you set (say, 7–14 days). This one setting neutralizes a large share of the attack window, because malicious registry uploads are typically detected and removed within days.

4. Dependency scanning in CI

Scanners such as Socket, Snyk, and GitHub's Dependabot flag suspicious packages: install scripts, obfuscated code, sudden maintainer changes, known malware signatures. Socket in particular targets supply chain behavior — a brand-new package that reads environment variables and opens network connections at install time gets flagged even without a known signature. Integration is measured in hours, and the checks run on every pull request from then on.

5. A private registry proxy, for larger teams

A proxy registry (Verdaccio is free; JFrog Artifactory and Sonatype Nexus are the commercial options) puts a controlled gate between developers and the public registry. Combined with scoped internal package names, it also closes the dependency-confusion path. This is the heaviest option — roughly a day of setup plus ongoing maintenance — and it makes sense once a team is past a handful of developers or ships anything regulated.

One thing that does not work as a primary defense: prompting the model to "only use popular, well-known packages." It reduces hallucinations but does not eliminate them, and it leaves the decision inside the same system that made the error. Verification has to live outside the model.

Alternatives and Trade-offs

Ban AI assistants entirely. This closes the slopsquatting door but throws away real productivity — GitHub's controlled study of Copilot measured developers completing a benchmark task 55% faster with the assistant. Paying that tax to avoid a risk that two minutes of verification also avoids is a poor trade for most teams.

Allowlist-only dependencies. Some regulated environments permit installs only from a pre-approved internal list. This is the strongest posture and the most expensive: every new library needs a review cycle, which can add days to tasks that should take hours. Reasonable for fintech and healthcare backends; overkill for a marketing site.

Scanners only, no process. Tooling without the human verification habit is reactive — scanners catch known-bad patterns, but a freshly registered package with a delayed payload can pass an automated check. The two-minute registry inspection catches what the newness itself reveals.

Honest take: no single layer is sufficient, and the most effective control is also the least glamorous one — a team norm that AI-suggested package names get the same scrutiny as a link in an unexpected email. The tooling layers exist to catch the day someone skips the norm.

Key Takeaway for Business

  • AI hallucinated packages are a real, measured attack surface, not a hypothetical. Research across 576,000 code samples found roughly 1 in 5 suggested packages did not exist, and 43% of the fake names recurred consistently — consistent enough for attackers to farm.
  • The economics favor defenders who act early. The full defensive stack — verification habit, enforced lockfiles, minimum-age gate, CI scanning — costs a small team a day or two of setup. The average breach it guards against costs millions and, more concretely, can hand an attacker your deployment keys.
  • Keep the assistants, add the checkpoint. The productivity gains from AI coding tools are worth keeping. The fix is not less AI — it is refusing to let any tool, human or machine, add a dependency to your product without thirty seconds of proof that it is what it claims to be.

This article is based on publicly available sources and may contain inaccuracies.

Related articles

✦SqueezeAI
  1. Slopsquatting exploits AI hallucination rather than human error: attackers register package names that models repeatedly invent, so malicious code is delivered automatically to any developer who follows the AI's install command without verification.
  2. A USENIX Security 2025 study across 576,000 generated code samples found that 19.7% of recommended packages did not exist, producing over 205,000 unique hallucinated names — a ready-made target list for attackers.

Powered by B1KEY