Sub topic 5
Slopsquatting, Typosquatting, and Dependency Confusion
This chapter assumes you can install packages with pip or npm, know that PyPI and npm are public registries where anyone can publish, and have used an AI coding assistant. Three attacks abuse the same weakness: a package manager installs whatever a name resolves to. They differ in how the attacker gets that name in front of you.
The shared mechanism
A package manager looks up a name in a registry and installs the match. It does not check whether you meant that package. Each attack arranges for a malicious package to be the match. If the package has an install script, it can run code on your machine (see the earlier chapter on install-time code).
Slopsquatting
Slopsquatting exploits names that a language model invents. The attacker collects names that models hallucinate, registers one on a public registry, and waits. The name was not a mistake by the victim. The victim copied a name from a suggestion that looked reasonable.
Two properties make it workable:
- Some hallucinated names recur across many prompts, so an attacker can predict which names are worth registering.
- The name often sounds plausible, such as a "helper" package for a well-known library.
Typosquatting
Typosquatting relies on human typing errors. The attacker registers a name close to a popular one, such as requets for requests. The victim has to mistype the name or copy it from a page where the typo was planted.
Dependency confusion
Dependency confusion targets private packages. A company uses an internal package called acme-billing-utils. If the build is configured to check a public registry as well as the internal one, an attacker can publish acme-billing-utils publicly with a higher version number. Some resolvers prefer the higher version, so the build installs the attacker's copy.
The name is real, but it exists in two places.
Side-by-side comparison
| Attack | Where the name comes from | What the victim does | Main target |
|---|---|---|---|
| Slopsquatting | A model's invented suggestion | Installs a name that never existed | Anyone following AI suggestions |
| Typosquatting | A near-miss of a popular name | Mistypes or mis-copies a name | Anyone typing names by hand |
| Dependency confusion | A real private package name | Nothing unusual; the build resolves it | Organizations with internal packages |
Spotting the differences in practice
The attacks call for different checks.
- Slopsquatting: the package is often new and has few releases. Check its age and history before installing. The
pypi_summaryscript in the verification chapter does this. - Typosquatting: compare the name character by character with the one in the official documentation.
- Dependency confusion: check that internal names are reserved or scoped. On npm, use a scope you own, such as
@acme/billing-utils. On Python, configure the resolver to take internal names only from the internal index.
Why the distinction matters
Controls that stop one attack may miss another. Careful typing does nothing against a suggestion you copy and paste. Scoped internal names do nothing against a hallucinated public name. Hash pinning and lockfiles, covered in a later chapter, help with all three, because a new name cannot enter the build without a deliberate change to the lockfile.
Exercise
Your team uses an internal Python package named acme-metrics. A teammate asks an AI assistant for a library to parse a niche log format. The assistant suggests logparse-ultra, which does not exist on PyPI. Which attack does registering logparse-ultra represent, and which attack would registering acme-metrics on PyPI represent? What control would address the second?
Show answer
Registering logparse-ultra is slopsquatting, because the name comes from a model's invention. Registering acme-metrics on PyPI is dependency confusion, because it duplicates a real private name. To address it, configure the build so internal names resolve only from the internal index, or reserve the name on the public registry.