AI’s Habit of Making Things Up Becomes a Security Nightmare
AI coding assistants have a well-known flaw: they hallucinate. Ask one to recommend a popular library or tool, and it might return a name that sounds legitimate but doesn’t actually exist. That quirk has always been annoying. Now, researchers have turned it into a weapon.
The attack is called HalluSquatting, and it’s disturbingly simple. The idea: figure out which fake names a given AI model reliably invents, register those names on package repositories before anyone else does, and then wait for the assistant to recommend your malicious package to an unsuspecting developer. When the developer’s machine installs it, the malware executes.
The research, led by a team of security experts, demonstrates a new class of supply chain vulnerability — one that exploits the very thing we’ve been told to tolerate as a harmless side effect of generative AI.
How HalluSquatting Works: The Three-Step Trap
The attack unfolds in three stages. First, the attacker probes a coding assistant — like GitHub Copilot or any large language model trained on code — to find packages it hallucinates. This means asking it repeatedly for package recommendations and recording the names it invents.
Second, the attacker registers those hallucinated package names on real package registries such as PyPI (for Python) or npm (for JavaScript). They upload a package that includes functional code — but also a hidden payload: a botnet client, a backdoor, or crypto miner.
Third, the attacker waits. When a developer asks the same AI assistant for that package, the model confidently suggests the hallucinated name. The developer runs a pip install or npm install command. The package downloads. The malware activates. And the developer’s machine becomes part of a botnet.
Why This Is Harder to Spot Than Traditional Typosquatting
Traditional typosquatting relies on misspellings — registering requrests instead of requests. Developers can catch those with a careful eye. But HalluSquatting packages don’t resemble any real project. They’re entirely fabricated names that the AI invented. A developer has no reason to be suspicious: the name looks like something that should exist, and the AI seems confident about it.
“The assistant doesn’t know it’s wrong,” the researchers note. “It’s just predicting the next token. But the developer trusts it.”
The Scale of the Problem: Thousands of Hallucinated Packages
The research team tested multiple AI coding assistants and found that they consistently hallucinated package names at alarming rates. In one experiment, a model invented fake package names for over 20% of queries about niche libraries. Across all tests, the researchers identified thousands of unique hallucinated package names that could be registered by an attacker.
Some of these packages were hallucinated repeatedly — the same fake name appearing across multiple sessions with different users. That reliability is exactly what makes the attack viable. An attacker doesn’t need to guess; they can just ask the AI, record the answer, and register the name.
Real-World Implications: Botnets and Beyond
The attack isn’t theoretical. The researchers demonstrated a proof-of-concept by registering a hallucinated package on PyPI, complete with a benign payload that phoned home to a server they controlled. Within days, the package was downloaded by automated build systems that had been prompted by AI assistants.
In a real attack, the payload could be a botnet client — turning every infected developer machine into a node for DDoS attacks, credential theft, or cryptocurrency mining. The potential for lateral movement is significant: a compromised developer machine often has access to production servers, source code repositories, and deployment pipelines.
This is a supply chain attack that doesn’t require compromising a legitimate package. It creates a fake one from scratch, using the AI’s own hallucination as the attack vector.
What Developers Can Do Right Now
There is no easy fix. The underlying issue — that AI models hallucinate — is a fundamental limitation of current technology. But developers can take practical steps to reduce risk:
- Verify before installing: Always check whether a recommended package exists on the official registry before running an install command. A quick search on PyPI or npm takes seconds.
- Use package pinning: Lock dependencies to specific versions and hash values. This prevents a malicious package from being swapped in later.
- Run in sandboxed environments: Execute AI-suggested code in isolated containers or virtual machines, especially when it involves installing new packages.
- Treat AI suggestions as starting points: Consider AI recommendations as research suggestions, not trusted answers. Cross-reference with documentation or community resources.
The researchers also suggest that package registries could implement proactive scanning for newly registered packages that match hallucinated names from popular AI models. But that would require cooperation between AI companies and registry maintainers — something that doesn’t exist yet.
The Bigger Picture: Hallucination as an Attack Surface
HalluSquatting is part of a growing recognition that AI hallucinations aren’t just a quality problem — they’re a security problem. When a model confidently produces false information, and that information is acted upon by a human or an automated system, the consequences can be severe.
This attack is specific to coding assistants, but the principle applies more broadly. Any AI system that generates plausible-sounding but false references — citations in academic writing, product recommendations in e-commerce, configuration settings in DevOps — could be exploited in a similar way.
For now, the coding assistant space is the most vulnerable. Developers are trained to trust their tools. And an AI that sounds certain is very persuasive. The HalluSquatting research is a reminder that in the rush to adopt generative AI, we’ve introduced a new class of attack that no one was watching for.
The question isn’t whether attackers will exploit this. They already are. The question is how quickly the industry can adapt.