Sub topic 1
Hallucinated Package Names and Slopsquatting: How AI Coding Tools Can Pull Malicious Dependencies
Prerequisites
This chapter assumes basic use of pip or npm, familiarity with public package registries, and experience using an AI coding assistant.
How a Package Name Becomes Installed Code
A package manager turns a name into files that run on your machine. For example:
python -m pip install requestsThe manager contacts a configured registry, finds metadata for requests, resolves its dependencies, selects compatible versions, downloads package archives, and installs them into the environment. A lockfile can constrain the versions and file hashes used during this process.
Why Installing a Package Can Run Attacker Code
Installation is not always file copying. Some packages run build backends, setup hooks, or lifecycle scripts. These steps may execute commands while the package is being built or installed. Later, the application can run more code when it imports the package.
An attacker can use this code to read environment variables, alter files, contact a server, or steal credentials available to the install process. The package does not need to look suspicious in the application source because the dangerous behavior can happen before the application starts.
Why Language Models Invent Package Names
Language models generate likely text from patterns in their training data. They do not automatically query PyPI, npm, or your private registry. When asked for a library, a model may combine a real project name with a plausible suffix, or confuse a package's import name with its distribution name.
A confident recommendation therefore does not prove that a package exists. If a developer installs the suggested name without checking it, the name becomes an opportunity for an attacker.
Slopsquatting: Registering Invented Names
Slopsquatting is the practice of registering package names hallucinated by language models. The attacker publishes a package under a name that developers may copy from generated code. The package can then execute malicious code during installation or use.
This differs from typosquatting, which targets human typing mistakes, and dependency confusion, which exploits the precedence between public and private registries. Slopsquatting targets machine-generated suggestions.
Exercise
Why is a plausible package name unsafe to install without checking?
Show answer
The name may not be real, or an attacker may have registered it specifically because an AI tool recommended it.