← Back to Learn
SecurityIntermediate6 min read

Identifying & Eliminating LLM Dependency Hallucinations

A step-by-step verification guide for package.json imports to prevent supply-chain attacks from fake AI-generated package names.

LLMs frequently hallucinate non-existent npm and PyPI package names (a vulnerability known as Slopsquatting). Attacker networks monitor public AI output patterns and register these missing package names on public registries with malicious payloads.

How Package Hallucination Happens

When an AI model generates code for specialized tasks, it often constructs plausible-sounding import paths:

typescript
// DANGER: Non-existent package hallucinated by LLM
import { StripeAuthAdapter } from '@auth/nextjs-stripe-adapter';

If an attacker registers @auth/nextjs-stripe-adapter on npm before you audit your imports, running npm install pulls malicious code straight into your production server environment.

3-Step Package Verification Checklist

1.Verify Package Registration Dates: Inspect npm package registration dates for any newly added dependency. Packages registered within the last 7 days require manual verification.
2.Lock Version Numbers: Never use loose floating dependencies (^ or ~). Lock exact version numbers in package.json.
3.Automate Import AST Audits: Use automated static scanners to parse every import and require call in your codebase against verified registry manifests.

Up Next

Refactoring AI Code Slop: Pruning Boilerplate in Next.js

Read Guide →