Day 5 of 1060 minShell WalkerHands-on lab
Day 5: Package Hallucination and Slopsquatting
Taught by Mr Elite Updated
By the end of today you can
- Explain why AI models invent package names and how slopsquatting turns that into an attack
- Check a package's age, downloads, maintainers and repository before installing it
- Inspect a package for install scripts without running it
- Write and apply a five-step package vetting routine
Warm-up
Answer from memory first, then tap to check. Recalling yesterday is what makes it stick.
Why is the context window a trust boundary, and what should you do before pasting a log into a prompt?
It is data sent to a third party and copies may persist. Review it and replace secrets with placeholders first.
If you realise you pasted a real API key into a prompt, what is the correct response?
Rotate the key. Treat it as exposed, because deleting the chat does not guarantee the copies are gone.
You ask your assistant for a quick way to parse a niche file format. It writes tidy code and tells you to run npm install followed by a package name that sounds perfectly sensible. You have never heard of it, but the assistant sounded sure, so you press enter.
That package may not have existed an hour ago. Models invent plausible names, and they tend to invent the same ones repeatedly. An attacker who notices can register that name and wait. Today you learn to check a package before it ever touches your machine.
Yesterday we guarded what goes in. Today we guard what comes in
On day 4 we treated the prompt as a trust boundary and reviewed what we sent out. Today the direction flips. The assistant's output contains names, and a package name is an instruction to download and run someone else's code. That is a second trust boundary: what we take in.
A package is not just a library. When you install it, you often run its install scripts, and later you run its code with your user's permissions, inside your project. So a suggested name deserves the same suspicion as a stranger's USB stick.
Think about what your user account can reach. Your project files, your environment variables, your SSH keys and your cloud credentials are often all readable by anything you run. Code from a package inherits that reach the moment it executes. So the question is never only whether the library works. It is whether you are willing to hand a stranger the keys to your account.
- Hallucination
- When a model produces something that sounds right but is made up, such as a package that does not exist.
- Slopsquatting
- Registering a package under a name that AI tools tend to invent, so developers who trust the tool install your code.
- Typosquatting
- The older trick of registering names that look like real ones, such as reqeusts instead of requests.
- Registry
- The public index of packages, such as npm or PyPI.
Why models invent names and how the attack works
A language model predicts likely text. It has seen thousands of package names, so it learns what a name in a given area looks like. Ask for a tool to convert one niche format to another and it may stitch together something like format-converter-utils. It reads right, so the model writes it with full confidence.
The key point is repetition. Similar prompts tend to produce similar invented names. That makes the names predictable, and predictable is what an attacker wants.
There is a second, quieter version of the problem. Sometimes the package is real but wrong: an abandoned project, or a lookalike of the one you meant. The model cannot tell you which, because it has no live view of the registry. It is only guessing from patterns in its training data, so every name it gives you is a claim to verify.
Quick check
Why do attackers care that models repeat the same invented names?
Predictability means one malicious registration can reach everyone whose assistant makes the same suggestion.
Watch me do it: vetting a package without installing it
Now I will show you the checks. Everything here only reads information from the registry. Nothing is installed or run. I will use npm and a well known package, express, so you can see what a healthy result looks like. Python users, I give the pip equivalent after. You need Node.js and npm installed.
First, open a terminal and confirm your tools are present. Run node -v and npm -v. Each should print a version number such as v20.11.0 and 10.2.4. If you see command not found, install Node.js from nodejs.org, close the terminal, open a new one and try again.
npm view express time.created time.modified maintainers repository.urlWhat just happened: npm asked the registry for four fields and printed them. For a healthy package the created date is old, the modified date is fairly recent, a handful of maintainers are listed, and the repository line ends in a github.com address. Paste that address into your browser and confirm the project is real and busy.
npm view express scripts
npm view express dist.tarballcurl -s https://api.npmjs.org/downloads/point/last-week/expressnpm view this-package-should-not-exist-xyz-98431 namepip index versions requests
curl -s https://pypi.org/pypi/requests/json | python3 -c "import sys,json; d=json.load(sys.stdin)['info']; print(d['name'], d['author'], d['home_page'], d['project_urls'])"Metadata is a good first filter, but you can go one step further and read the code itself. The npm pack command downloads the package archive into the current folder without installing it and without running its scripts. Do this inside a throwaway folder so nothing mixes with your project.
mkdir vet-test && cd vet-test
npm pack express
tar -xzf express-*.tgz
cat package/package.jsonIf npm pack prints a filename ending in .tgz and a folder called package appears, it worked. Open package/package.json and search for preinstall, install or postinstall. Reading files with cat is safe, because nothing runs. When you finish, leave the folder with cd .. and delete vet-test.
Quick check
A package exists, was created three days ago, has 40 downloads and an install script that runs a shell command. What do you do?
New age, low use and an install hook are all warning signs, so find a trusted alternative.
Lockfiles and install scripts
A lockfile (package-lock.json or poetry.lock, for example) records the exact versions and content hashes you installed. It stops a later install silently pulling a different, newer version. Commit it, and review changes to it in pull requests, because an AI-written change that adds a dependency shows up there.
Install scripts are the other danger. They run code the moment you install. npm lets you inspect first and also lets you turn them off.
npm install --ignore-scripts some-package
npm config set ignore-scripts trueTo confirm the setting stuck, run npm config get ignore-scripts. It should print true. If it prints false, the config command did not save, so check that you typed it exactly and run it again. Treat this as a safety net, not a replacement for checking the package first.
git diff package.json package-lock.jsonIn the diff, lines starting with a plus sign are additions. Under dependencies you might see a plus line such as a package name with a version number. If you did not ask for it and cannot explain it, stop. Run the vetting checks on that name before the change goes any further.
Lab: AI Package Hallucination and Slopsquatting
Now you apply this in the browser lab. It simulates an assistant recommending a package that does not exist, and shows what happens when someone claims the name. Work only inside the lab environment. Do not try this routine against real registries by registering names.
Go in with the five checks in front of you: existence, age, maintainers and repository, install scripts, popularity. Run them in that order and write down what each one tells you. Note which single result first made you doubt the package, because that is the signal you will build your routine around in the mission.
Your turn
AI Package Hallucination
This lab lets you see the whole slopsquatting chain safely, from an assistant inventing a name to the consequence of an attacker claiming it. It is the quickest way to feel why a name alone is not evidence of trust.
What to try
What to notice
- How convincing the invented name looks at first glance
- Which signals (age, downloads, maintainer, repository link) disagree with the name's apparent trustworthiness
- Whether the dangerous behaviour sits in an install script or in normal code
If it did not work
Assuming that if a package exists, it must be the right one
Existence proves nothing. Check age, maintainers, downloads and the repository link every time, especially for names you did not choose yourself.
Trusting download counts alone
Counts can be inflated or old. Combine them with age, maintainer history and a real repository whose code matches the package.
Running npm install to see what the package does
Installing is the dangerous step. Inspect with npm view, or download the tarball and read it, before any install.
Ignoring lockfile changes in AI-written pull requests
Read the lockfile diff. Any new dependency needs a reason, and unexpected additions should be questioned.
Recap
- A package name is an instruction to run someone else's code, so it is a trust boundary.
- Models invent plausible names and repeat them, which makes slopsquatting practical.
- A missing package is a warning, and a freshly registered one is not proof of safety.
- Check existence, age, downloads, maintainers and repository before installing.
- Install scripts run automatically, so inspect them first or disable them with ignore-scripts.
- Commit lockfiles and review dependency changes like code.
Cheat sheet
npm view <pkg> time.created maintainers repository.url- Shows age, publishers and source repo without installing
npm view <pkg> scripts- Lists install hooks that would run automatically
npm pack <pkg>- Downloads the archive without installing, so you can read it
npm install --ignore-scripts <pkg>- Installs without running lifecycle scripts
npm config set ignore-scripts true- Disables install scripts by default
pip index versions <pkg>- Lists published versions on PyPI
git diff package-lock.json- Reveals new or changed dependencies before commit
E404 on lookup- Name is unregistered, so the suggestion may be hallucinated
Before the next day
Mission: Five-step package vetting routine
Finish the lab, then turn what you did into a routine you can repeat in under five minutes. Prove it works by applying it to one real package your own project already uses, so you see what a healthy result looks like on a package you depend on.
About 35 min
You are done when: vetting-routine.md with five commands and a stop rule, plus vetting-results.md showing the routine applied to one real package.
Want more? Write a small shell script that takes a package name, runs the npm view checks and prints a pass or flag for age, scripts and repository.
Quiz
4 questions. Your score is saved with your progress.
1. What makes slopsquatting different from typosquatting?
Typosquatting relies on human typos. Slopsquatting relies on names a model keeps inventing.
2. Which command is safest for investigating an unfamiliar npm package?
npm view only reads registry metadata. The others download or run code.
3. Why review lockfile changes in an AI-written pull request?
The diff shows new dependencies that the assistant may have added without telling you.
4. A hallucinated name returns E404. What is the right conclusion?
An unclaimed name is exactly what a slopsquatter wants. Treat the suggestion as wrong and find a real alternative.
Finish the day
Mark the day complete to save your progress.
Next: Day 6 moves from what the assistant suggests to what it can do. We configure a coding agent with least privilege and work out how far a compromised agent could reach.
Your notes
Private to this device. Write what you want to remember from today.