Sub topic 6
Walking through the attack chain end to end
This chapter assumes you know how package managers fetch names from public registries and why install steps can run code. It also assumes you know why models sometimes invent package names. Here we join those pieces into one sequence and look at where each step can be stopped.
The six stages
A slopsquatting attack has no exploit in the usual sense. Each stage is normal behavior of a model, a registry, or a package manager. The attack works because the stages line up.
Stage 1: The model suggests a missing name
A developer asks for help with a task, such as parsing a file format. The model answers with code that imports or installs a package called, for example, fastjson-utils. The name looks plausible because it combines common words from real package names. No such package exists on the registry.
A single wrong name is not enough for an attacker. What matters is whether the model produces the same name again. Research on this problem has found that many hallucinated names recur across repeated runs of the same prompt. Repeatable names are the ones worth registering.
Stage 2: The attacker finds the repeatable names
The attacker does not need access to your chat. They can send many common coding prompts to popular models, collect every package name in the answers, and query the registry for each one. A 404 means the name is free. Names that appear again and again are the best targets. The pypi_summary script from the earlier verification material works the same way from the other side: a 404 is a warning for you and an opening for them.
Stage 3: The attacker registers the name
Registering on PyPI or npm is free and fast. The attacker publishes a package under the hallucinated name. It often does something useful, or at least imports cleanly, so the developer sees no error. The harmful part sits in code that runs at install time, such as a setup.py in a source distribution or an npm postinstall script.
Stage 4: The developer or agent installs it
The developer copies the suggested command, pip install fastjson-utils or npm install fastjson-utils. The package manager resolves the name against the public registry. It cannot tell a legitimate project from a freshly registered one. A coding agent that installs dependencies on its own does the same thing with no human reading the name.
Stage 5: Install-time code runs
The install step runs with the permissions of the current user. Typical goals are:
- Read environment variables, which often hold cloud keys and API tokens.
- Copy SSH keys,
.npmrc,.pypirc, or browser credentials. - Open a reverse connection or add a persistence mechanism.
Because this happens during install, the developer may never import the package. Deleting it afterward does not undo what already ran.
Stage 6: The package spreads
The developer adds the name to requirements.txt or package.json and commits it. CI runners, teammates, and production builds now install it too. A CI runner often holds more powerful secrets than a laptop, so the blast radius grows with each copy.
Where the chain can break
Each stage has a control that interrupts it. Later chapters cover these in detail.
| Stage | What breaks the chain |
|---|---|
| 1. Suggestion | Treat every suggested name as unverified |
| 2. Discovery | Nothing on your side; the attacker works from public data |
| 3. Registration | Registry malware scanning and name-reservation policies |
| 4. Install | Check the name and registry history before running the command |
| 5. Execution | `npm ci --ignore-scripts`, hash pinning, isolated build environments |
| 6. Spread | Code review of dependency changes, lockfiles, allowlists |
Stages 1 to 3 happen outside your control. Your effective options start at stage 4, so that is where most of your effort belongs.
A worked example
Suppose an assistant suggests pip install flask-session-guard. Before running it, you check the name:
python pypi_check.py flask-session-guardHere pypi_check.py is the script from the earlier verification material. If it prints NOT FOUND, the model invented the name and you should not install it. If it prints one release and a first-upload date from last week, the name exists but looks suspicious. A package a model recommended confidently, yet nobody has used before this week, matches the slopsquatting pattern. Look for the real library the model was imitating and install that instead.
Exercise
A model suggests an npm package. You run npm view and see it was first published two days ago with a single version. Which stage of the attack chain have you possibly caught, and what should you do next?
Show answer
You may have caught the result of stage 3, where an attacker registered a hallucinated name. Do not install it. Search for the established package that does the job, confirm it by its history and project page, and install that one from a lockfile with npm ci --ignore-scripts.