Dependency Hallucination: The Silent Security Risk in AI-Generated Code

August 5th, 202610 min read

Imagine asking an AI coding agent to add Stripe payments or OAuth authentication to your Next.js project. The agent outputs a clean import statement: import { StripeAdapter } from '@auth/nextjs-stripe-adapter';. You run npm install, test it in development, and move on.

There is only one problem: @auth/nextjs-stripe-adapter does not exist on npm. The AI hallucinated the package name based on plausible naming patterns.

⚠️ Shipping an AI-Generated App Soon?

Detect Package Hallucinations & Code Debt Before You Launch

Run a 10-second AST scan on your repository to detect hallucinated npm packages, hardcoded secrets, and AI code slop before you go live.

⚡ Audit My Repo ($19)

While an uninstalled package will fail your build, a malicious supply-chain attacker watching AI hallucination patterns can register that exact missing package name on npm and publish malware inside it.

How Slopsquatting Works

Security researchers call this vulnerability Slopsquatting or AI Package Typosquatting. When LLMs generate code, they frequently construct hypothetical package names by combining popular library prefixes (e.g., @auth/, react-use-, next-extra-).

```json // Real package.json snippet with a hallucinated dependency { "dependencies": { "next": "^16.0.0", "react": "^19.0.0", "@auth/nextjs-stripe-adapter": "^1.0.4" // HALLUCINATED PACKAGE! } } ```

If an attacker registers @auth/nextjs-stripe-adapter on the public npm registry before you audit your imports, running npm install will pull down the attacker's code directly into your production build pipeline.

🔒 Verify Package Dependencies Before Deploying

Our AST scanner cross-references every imported package against verified registry manifests to detect non-existent and unpinned dependencies.

Audit My Repo ($19)

3 Steps to Immunize Your Repository

  • Check package registration dates: If a package in your package.json was registered on npm within the last 7 days, inspect the author credentials manually.
  • Lock dependency versions: Pin exact package versions in package.json rather than using floating ranges (^ or ~).
  • Automate AST import verification: Run static AST rules that parse all import and require statements across your source files and verify them against official registry manifests.

Protect Your Supply Chain Before Launch

Get a full Supply Chain & SAST Security audit report for your public or private GitHub repository.

⚡ Audit Your Repo ($19)

FTC Disclosure: Outbound links to code tools on this page may be affiliate or referral tracking links. We may receive commissions or metrics value if you purchase via these links, which supports running this tool at no extra cost to you.