DevHelper is a coding assistant. It writes code and installs the packages it recommends. Arjun asks it to add JWT session security to his Flask app. It confidently recommends flask-session-shield, a package that sounds right but doesn't exist.
AI models invent package names, and they tend to invent the same names again and again. Attackers watch for those names and register them with a malicious install hook. That's slopsquatting. Here, the "new" package's install hook reads the developer's secrets and posts them out.
Why it worked
- Whatever the model named got installed. Nothing checked the package was real, established or approved.
- Install hooks ran with the developer's secrets in reach.
A package name from a model is a suggestion, not a fact (OWASP LLM03 Supply Chain, LLM09 Misinformation).
The fix, in code
MIN_AGE_DAYS, MIN_DOWNLOADS = 90, 1000
def pip_install(args, state):
name = args["package"]
meta = lookup(name)
# FIX 1: check the name is real and established before anything else.
if not meta:
return "BLOCKED: no such package (the model may have invented it)"
age = (date.fromisoformat(TODAY) - date.fromisoformat(meta["first_uploaded"])).days
if age < MIN_AGE_DAYS or meta["downloads_last_month"] < MIN_DOWNLOADS:
return f"BLOCKED: {name} is {age} days old with {meta['downloads_last_month']} downloads. Possible slopsquatting."
# FIX 2: anything not already in requirements.lock waits for a human review.
if name not in LOCK:
return "BLOCKED: held for review (not in requirements.lock)"
# FIX 3: approved packages install from the lockfile, hashes pinned, with no install hooks and no secrets.
return f"installed {name}"
Same request, run again: the brand-new package is blocked as a possible slopsquat, and nothing installs without review.
Run the lab yourself
git clone https://github.com/usinha79/hack-it-then-fix-it
cd hack-it-then-fix-it/ep17-slopsquatting
pip install -r requirements.txt
python vulnerable/app.py # http://localhost:5000, then ./attack.sh
python fixed/app.py # same request, the install is blocked
Everything is local and simulated. The package index is a folder, "installing" reads a JSON file, and the lab simulates the hook using only a fake .env.lab. Nothing is downloaded or executed. flask-session-shield is a name invented for this lab: don't look for it, or install it, from the real PyPI. Full lab: github.com/usinha79/hack-it-then-fix-it
Take-home checklist
- Verify every package an AI suggests: that it exists, its age, downloads, maintainers and source repo.
- Never let an agent add dependencies without review. Use lockfiles with hashes (
pip install --require-hashes). - Use a private registry or proxy with an allowlist for CI and agents.
- Run installs and coding agents without access to real secrets.
Catch up on Module 2
This episode is part of Module 3 of Hack It, Then Fix It. New to the series? Module 2 covers seven real AI agent attacks, each one hacked and then fixed in code, back to back:
Hack It, Then Fix It is a series where I build a small AI app with a real flaw, break it, fix it in code, and run the same attack again to prove the fix holds. Everything shown uses fake data on my own machine. Only test systems you own or are authorised to test.
Top comments (0)