Sub topic 4
Slopsquatting: Registering the Names Models Invent
This chapter assumes you have used pip or npm, know that PyPI and npm are public registries where anyone can publish, and have asked an AI assistant for code. It builds on the earlier chapters about how names resolve to installed code and why models invent names. Later chapters compare related attacks and cover verification and controls in detail.
What slopsquatting is
Slopsquatting is the practice of registering a package name that language models tend to hallucinate, then putting malicious code behind it. The name combines "slop" (low-quality AI output) with "squatting" (claiming a name you have no right to). Seth Larson, a Python Software Foundation security developer, is credited with coining the term.
The attacker does not need to break anything. Public registries accept new names on a first-come basis, and the model has already supplied the lure. The attacker only has to publish before a developer asks for that name.
A hallucinated name is a free gap in the registry. Nobody owns it, no maintainer reviews it, and no existing user base would notice an oddity. The first account to publish becomes the owner.
Why the attack is plausible
Three conditions must hold for the attack to work.
- The model suggests names that are not registered. A model completes text based on patterns. A name like
flask-jwt-helpersfits the pattern of real packages, so the model can produce it with the same confidence as a real one. - The same fake names come back. If every hallucination were unique, an attacker could not predict anything. Research on this problem (a 2024 study by researchers at the University of Texas at San Antonio, Virginia Tech, and the University of Oklahoma that tested 16 code models) found that a large share of hallucinated names reappeared across repeated runs of the same prompt. Treat the exact percentages as dependent on the model, prompt set, and date. The finding that matters is that many names are repeatable, and repeatable names can be harvested.
- Someone installs without checking. A developer or agent copies the install command from the answer and runs it.
If the first condition fails, there is nothing to claim. If the second fails, the attacker is guessing. If the third fails, the claimed package sits unused. Defenses can target any of the three, but the third is the one you control directly.
How an attacker finds names worth claiming
An attacker has several ways to collect candidate names. None needs special access.
- Prompt the models directly. Ask popular assistants thousands of common programming questions, extract the package names from the answers, and check each name against the registry. Any name that returns "not found" is a candidate.
- Rank by frequency. A name suggested in many runs is more valuable than one seen once.
- Watch public output. Blog posts, forum answers, tutorials, and generated documentation sometimes contain unchecked suggestions. Names that appear there are already in circulation.
- Mine failed installs. Error messages posted in issue trackers and Q&A sites show names that people tried and could not find.
The registry check is the same operation a defender uses. The code below does it for one name.
import urllib.error
import urllib.request
def is_registered(name):
url = f"https://pypi.org/pypi/{name}/json"
try:
with urllib.request.urlopen(url, timeout=10):
return True
except urllib.error.HTTPError as err:
if err.code == 404:
return False
raise
print(is_registered("requests"))A 404 response means the name is free. For an attacker that is a target. For you, it means the suggestion should not be installed until you understand where it came from.
What the attacker publishes
A claimed package typically takes one of three forms.
| Form | What it does | Why it works |
|---|---|---|
| Empty or placeholder package | Reserves the name, delivers nothing yet | Cheap, and the attacker can push a malicious update later |
| Install-time payload | Runs code during installation (for example, a `setup.py` in a source distribution, or an npm `postinstall` script) | Runs before the developer reads any code |
| Working look-alike | Provides the functionality the model described, plus hidden behavior | The developer's code runs, so nothing seems wrong |
The look-alike form is the hardest to notice. The developer asked for a JWT helper, got one, and the tests pass.
The placeholder form deserves attention too. Registries do not stop a package from changing after publication. A name that was harmless last month can ship a malicious release today. A one-time check of a package is therefore not permanent proof of safety.
A worked scenario
Suppose a developer asks an assistant how to parse a vendor's report format. The assistant answers:
pip install acme-report-parserNo package by that name existed when the model learned the pattern. An attacker who had been sampling model answers noticed the name and registered it. The package contains a plausible parser and a function that sends environment variables to a remote server on first import.
The developer runs the command. The package installs, the sample code runs, and the output looks right. Nothing alerts them. The sensitive data left the machine during that first import.
Notice what did not happen. No vulnerability in pip or in the registry was exploited. Every component behaved as designed.
Why it differs from a typical bug
Slopsquatting is a supply-chain attack that depends on a trust decision. Software vulnerabilities are usually defects in code you run. Here, the code is working as written, and the weak point is the step where a name is accepted as trustworthy.
This has two consequences.
- Patching does not fix it. You cannot update a library to close the gap. The fix is a process: verify the name, restrict what installs, and review the result.
- The scale is uneven. A typo affects one person. A hallucinated name that a popular model repeats can reach many people who never talk to each other, because each is getting the same answer from the same model.
Limits and uncertainty
Be careful with claims about this attack in either direction.
- Documented real-world harm is limited. Researchers have demonstrated the mechanism and measured hallucination rates. In one widely discussed case, a security researcher registered a package under a name that models kept suggesting, and it received thousands of downloads from people following those suggestions. That shows the exposure is real. It does not show that large numbers of attackers are doing this.
- Rates vary. Hallucination rates differ by model, language, prompt, and whether the model has search or retrieval tools. Open-source models in the 2024 study hallucinated more than commercial ones, and the study found rates differed by language. Do not quote a single number as if it applied to your tools.
- Models change. A name that was a hallucination last year may now be a legitimate package, and the reverse can occur. Check the registry at the time you install.
- A found package is not a safe package. An existing name may be a squat too. Existence is only the first check.
Edge cases
- Names that are real but unrelated. A model may suggest
parser-utilsfor one task, and the registry has a package with that name that does something else. This looks safe because the name exists. It is a mismatch, and you should read the package page. - Namespace and scope confusion. In npm,
@scope/nameandnameare different packages. A model that drops or invents a scope may point to a name that an attacker can register publicly. - Import name versus install name. In Python, the name you import can differ from the name you install (
import yamlcomes frompip install pyyaml). A model that mixes them up can generate an install command for a name that is not the real package. An attacker can register that wrong name. - Case and separator normalization. PyPI treats
my_pkg,my-pkg, andMy.Pkgas the same name. A variant is therefore not a separate squat target in Python, but npm names are stricter, so check each registry's rules. - Typos in the model's output. Models sometimes produce a near-miss of a real name. That overlaps with typosquatting, which the next chapter compares.
- Package removal. If a registry removes a malicious package, the name may return to the pool, and the same hallucination can attract a new claimant.
What to take from this
- Slopsquatting needs a model that repeats a name, a registry that allows anyone to claim it, and an install step that runs without a check.
- The attacker's cost is low, and the repeated model suggestion does the targeting.
- Existence on a registry is not evidence of trust. Age, history, maintainers, and release patterns matter, and a later chapter covers how to inspect them.
Exercise
A model suggests pip install fastjson-utils. A PyPI lookup returns a page showing one release, uploaded three days ago, with no linked source repository. Name two reasons this should not be installed yet, and say which of the three conditions for slopsquatting an install would complete.
Show answer
Reasons: the package is brand new with a single release, and it has no source repository to review, which fits a name claimed recently by someone other than an established maintainer. The name may also be a squat of a hallucinated suggestion, and the page gives nothing to show otherwise. Installing it would complete the third condition: someone installs the name without checking. The first two conditions (the model suggests an unregistered name, and the name repeats) have already been met.
Exercise
Why does patching your dependencies not protect against slopsquatting?
Show answer
The malicious package is not a flaw in code you already trust. It is a new package you chose to add. The problem is the decision to accept an unverified name, so the fix is a process (verify, pin, restrict install scripts, review), not an update.