Sub topic 5
Slopsquatting, Typosquatting, and Dependency Confusion
This chapter assumes you have used pip or npm, know that PyPI and the npm registry are public and open to anyone who wants to publish, and have read the earlier chapters on how a package name resolves to installed code and how language models invent package names. Here you will learn how slopsquatting differs from two older attacks, typosquatting and dependency confusion. You will also learn why the difference decides which defense works.
One weakness, three entry points
All three attacks rely on the same fact. A package manager turns a name into code, and on a public registry nobody checks whether the person who registered a name is the person you meant. The attacks differ in how the wrong name ends up in your install command or manifest.
| Attack | Where the wrong name comes from | Who makes the mistake | Name the attacker registers |
|---|---|---|---|
| Typosquatting | A human mistypes or misremembers a real name | The person typing | A near-miss of a popular name |
| Dependency confusion | The resolver picks a public package over a private one with the same name | The build configuration | The exact name of an internal package |
| Slopsquatting | A model invents a plausible name | The model, then the person or agent who trusts it | A name that no one has registered before |
The sections below take each attack in turn, then show where they overlap.
Typosquatting: betting on human error
Typosquatting predates AI coding tools by many years. The attacker registers names that look like popular packages and waits for typing slips. Common variants include:
- Transposed or dropped letters, such as
reqeustsforrequests. - Swapped separators, such as
python_dateutilversuspython-dateutil. On PyPI these two normalize to the same name, so this trick works better on registries that do not normalize. - Added or removed prefixes and suffixes, such as
requests-pyorurllib. - Look-alike characters, such as a digit
1in place of a lowercasel.
The attacker's payload usually imports and re-exports the real package, so the project still works. That makes the compromise hard to notice.
Typosquatting has two properties that matter for defense. First, the target is always a popular package, because that is where the typing volume is. Second, the set of candidate names is finite and can be computed. A registry or a scanner can generate likely typos of the top few thousand packages and compare them with new uploads. Registries do this today, which is why simple typos are caught more often than they used to be.
Dependency confusion: exploiting resolver rules
Dependency confusion was demonstrated publicly by Alex Birsan in 2021. It does not involve a mistaken name at all. The name is correct. The resolver is the problem.
Suppose your company has a private package called acme-billing on an internal index. If a build is configured to look at both the internal index and the public one, the resolver sees two candidates. Many resolvers choose the highest version number. An attacker who learns the internal name can publish acme-billing version 99.0.0 on the public registry. The build then picks the attacker's version, and the attacker's install-time code runs on your CI server.
The attacker learns internal names from leaked manifests, public repositories that reference internal packages, error messages, or JavaScript bundles.
This is where pip's two index options matter:
# Risky: pip considers both indexes and can pick the highest version from either
pip install --index-url https://pypi.org/simple/ \
--extra-index-url https://pypi.internal.example/simple/ \
acme-billing
# Safer: one index only. The internal index must proxy or mirror public packages too.
pip install --index-url https://pypi.internal.example/simple/ acme-billingFor npm, scopes bind a namespace to a registry:
# .npmrc: every @acme/* package comes from the internal registry only
@acme:registry=https://npm.internal.example/An unscoped internal name offers no such binding. Scoped names help only if you also own the scope on the public registry, or if the scope is bound to the internal registry as shown.
Slopsquatting: betting on model error
The term slopsquatting is credited to Seth Larson of the Python Software Foundation. The attacker registers a name that a language model tends to invent. No human typed anything wrong, and no resolver rule was abused. A model produced a name, such as fastjson-utils, that sounds like it should exist. A reader or an agent then ran the install command.
Three properties separate slopsquatting from typosquatting:
- The target is not a popular package. The invented name often has no real counterpart. A typo scanner that compares new uploads with the top packages will not flag it, because it resembles nothing.
- The names can be predicted by sampling. Research on code-generation models has found that many hallucinated names recur when the same prompt is run repeatedly. An attacker can prompt a model many times, collect the names that do not exist on the registry, and register the ones that come up most often. Typosquatters guess at human error, while slopsquatters measure model error.
- The victim is often not typing at all. With an assistant that runs shell commands, the install happens without a human reading the name. Later chapters cover this amplifier.
A researcher reported registering an empty package under a name that models kept suggesting. It was downloaded thousands of times, which shows how quickly a hallucinated name turns into real installs.
Where each attack enters the workflow
The diagram shows the common path from intent to installed code and where each attack inserts a wrong name.
The first two attacks change the name before lookup. Dependency confusion changes what the lookup returns for a correct name. This is the main reason the defenses differ.
Why the defenses differ
Each attack needs a different control.
- Typosquatting is reduced by copy-paste from the official project page, by tools that flag names close to popular packages, and by registry-side scanning of new uploads.
- Dependency confusion is reduced by configuration: one index, scoped registries, claimed names on the public registry, and lockfiles that record which source each package came from.
- Slopsquatting is reduced by verifying existence and reputation before installing. A name that exists only because someone registered it last week fails that check, even though it is spelled correctly and no resolver rule was abused.
Hash pinning and lockfiles protect against all three once a good set of dependencies is recorded. They do nothing for the moment when a new name is first added. That moment is where slopsquatting happens, because the model suggests a dependency that is not yet in the lockfile.
A rough classifier
The script below gives a first-pass label for a name. It is a teaching aid. It does not replace a registry check. It uses difflib from the standard library to detect near-misses of a list of well-known names, and a prefix list to flag internal-looking names.
import difflib
import sys
POPULAR = [
"requests", "numpy", "pandas", "urllib3", "cryptography",
"flask", "django", "boto3", "pytest", "setuptools",
]
INTERNAL_PREFIXES = ("acme-", "acme_")
def classify(name):
lowered = name.lower()
if lowered in POPULAR:
return "known popular package"
if lowered.startswith(INTERNAL_PREFIXES):
return "internal-looking name: check dependency confusion settings"
close = difflib.get_close_matches(lowered, POPULAR, n=1, cutoff=0.85)
if close:
return f"close to {close[0]!r}: possible typosquat or typo"
return "resembles nothing known: if it is also missing or brand new on the registry, treat as slopsquatting candidate"
if __name__ == "__main__":
for pkg in sys.argv[1:]:
print(f"{pkg}: {classify(pkg)}")Run it as python classify.py reqeusts acme-billing fastjson-utils requests. The first name is flagged as close to requests, the second as internal-looking, the third as resembling nothing, and the fourth as known. The third result shows the limit of similarity checks. Nothing about fastjson-utils looks wrong until you ask the registry about it.
Edge cases and overlaps
The categories blur in practice, and real incidents often do not fit one box.
- A model makes a typo-like error. A model may emit
python-dateutilsinstead ofpython-dateutil. This is both a hallucination and a near-miss of a popular package. A typosquat scanner may catch it, but only if the attacker's upload is checked at publication time. - A model invents an internal-sounding name. Asked to write code for a company codebase, a model may produce a name that matches your private naming scheme, such as
acme-auth-helpers. If the build uses--extra-index-url, this becomes a dependency confusion risk even though no internal package of that name exists yet. An attacker only has to guess the same pattern. - A name is real but wrong. A package may exist and still not be what the model meant. A different author may have registered
jwt-utilsyears ago. Existence checks alone do not catch this. You must also check age, release history, and whether the project page matches the functionality you expected. - Namespace rules differ. PyPI normalizes case, and runs of
-,_, and.collapse to one separator. npm names are lowercase and scoped names carry an owner prefix. These rules change which typo variants are possible and which names an attacker can claim. - Deleted and reclaimed names. If a maintainer deletes a package, the name may become available again on some registries. Registries now restrict this, but older projects may still list names that anyone could now claim. This is a fourth route to the same result and is not covered by the three labels above.
Choosing the right check
When a name is about to enter a manifest, ask these questions in order:
- Was it copied from the official project documentation, or did a model or a person recall it from memory?
- Does the registry have it, and when was it first uploaded?
- Is it close to a better-known package?
- Could a public package of the same name shadow a private one in this build?
Questions 2 and 3 are the checks that the tools in the next chapter automate. Question 4 is a configuration review. Question 1 decides whether you need the others, and it is the cheapest to ask.
Exercise
A build runs pip install --extra-index-url https://pypi.internal.example/simple/ acme-billing along with the default public index. Which of the three attacks does this configuration expose you to, and what is the smallest configuration change that removes the exposure?
Show answer
It exposes you to dependency confusion. pip considers both indexes and can select the highest version, so a public acme-billing with a high version number can win. The smallest fix is to use a single --index-url that points to an internal index that also proxies public packages, so only one source decides the result. Registering acme-billing on the public registry as a placeholder is a useful extra step.
Exercise
An assistant suggests pip install fastjson-utils. The name is spelled consistently, is not close to any popular package, and the registry shows it was first uploaded three days ago with one release. Which attack does this most resemble, and why would a typosquat scanner not flag it?
Show answer
It resembles slopsquatting. The name was probably invented by a model and then registered by an attacker. A typosquat scanner compares new names with popular ones, and fastjson-utils resembles none of them, so there is nothing to match. The registration date and the single release are the signals that matter, and they come from a registry check.