Sub topic 4
Slopsquatting: registering the names models invent
This chapter covers the attack itself: how an attacker turns a model's invented package name into a foothold on a developer's machine. It assumes you know how pip or npm installs a package by name, and that you have used an AI assistant to get code suggestions. The earlier chapters on name resolution, install-time code execution, and why models hallucinate names are background here.
What slopsquatting is
Slopsquatting is the practice of registering a package name that language models tend to invent, then publishing malicious code under that name. The term combines "slop" (low-quality AI output) with "squatting" (claiming a name you have no right to). When a model recommends a package that does not exist, the name is unclaimed. Anyone can register it on a public registry such as PyPI or npm, usually in minutes and for free.
The attack relies on two facts from earlier chapters:
- A package manager installs whatever the registry returns for a name. It does not check that the name is a good one.
- Installing can run code. A malicious package can execute during install, not only when you import it.
Why hallucinated names are exploitable
A random wrong answer would be hard to exploit. Hallucinated names are different in three ways.
- They repeat. Researchers who tested many models on many coding prompts found that when a model invents a name, it often invents the same name again for the same kind of prompt. A repeated name is a reliable target.
- They sound plausible. A name like
flask-json-utilslooks like something that should exist, so a developer is less likely to question it. - They are predictable. An attacker can ask models the same questions developers ask, collect the names that do not exist, and register the most frequent ones before any victim arrives.
The attacker does not need to break into anything. The model supplies the target list.
How the attack works
The attacker's work happens before any victim does anything.
- Prompt one or more models with common coding questions and record every package name they suggest.
- Check each name against the registry. A name that returns "not found" is a candidate.
- Rank candidates by how often they appear across prompts and models.
- Register the top names and publish a package that looks harmless, often with a README that copies a real project.
- Hide the payload in an install script or in code that runs on import.
- Wait. Developers and coding agents that follow a model's suggestion now install the attacker's package.
The attacker can also keep the package functional. Some malicious packages wrap or re-export a real library so the code the model wrote keeps working, which makes the compromise harder to notice.
A concrete check
You can see whether a suggested name is unclaimed by asking the registry. The script below, from the verification chapter's toolkit, treats a 404 as a warning sign.
import json
import re
import sys
import urllib.error
import urllib.request
NAME_RE = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]*")
def pypi_summary(name):
if not NAME_RE.fullmatch(name):
raise ValueError(f"invalid package name: {name!r}")
url = f"https://pypi.org/pypi/{name}/json"
try:
with urllib.request.urlopen(url, timeout=10) as resp:
data = json.load(resp)
except urllib.error.HTTPError as err:
if err.code == 404:
return None
raise
uploads = [
f["upload_time_iso_8601"]
for files in data["releases"].values()
for f in files
]
return {
"releases": len(data["releases"]),
"first_upload": min(uploads) if uploads else None,
"home_page": data["info"].get("home_page"),
}
if __name__ == "__main__":
for pkg in sys.argv[1:]:
info = pypi_summary(pkg)
if info is None:
print(f"{pkg}: NOT FOUND on PyPI (possible hallucination, do not install)")
else:
print(f"{pkg}: {info}")Run it with python check_pkg.py requests some-invented-name. A 404 means the name is free today. It does not mean the name is safe tomorrow, because an attacker may register it before you try again.
The reverse case matters more after an attack succeeds. A name that exists but has one release, a first upload date of a few days ago, and no real home page is a slopsquatting suspect. Existence on the registry is not proof of trust.
Common errors in reasoning
- "The package installed, so it must be real." Installation succeeds for attacker packages too. Success tells you only that the name is registered.
- "I'll just retry later if it's not found." A not-found result is the moment to stop and verify, not to wait for the name to be claimed.
- "The model's code ran correctly." A malicious package can forward calls to the real library and still run its payload.
- "It has a clean README." READMEs are copied easily and prove nothing about the uploaded code.
Exercise
A coding assistant suggests pip install fastjson-helpers. Your check script prints a release count of 1 and a first upload date two days ago. Why is this result a warning, and how does it relate to slopsquatting?
Show answer
The name exists, but a single recent release with no history is what a freshly registered attacker package looks like. If models were suggesting this name before it existed, an attacker could have registered it after seeing the suggestion. Do not install it. Look for the legitimate library you actually need, and inspect the package source and its publisher before trusting anything.