Vibe Code Guardian
← All posts

Package Vulnerabilities in AI-Generated Code: What Your AI Installs Without Asking

AI coding tools install npm packages fast. They also install outdated, vulnerable, or hallucinated packages without telling you. Here is how to audit what your AI added before it ships.

Aaron Allen·

The dependency list you never approved

You asked Cursor to add a chart. It wrote the component, imported a charting library, and updated package.json. You accepted the change. The app works.

What you did not see: the AI also pulled in three transitive dependencies, one of which has not been updated in four years and carries a known prototype pollution vulnerability. Another is a package that does not exist — the AI hallucinated the name, and npm happened to have a similarly named package uploaded by an attacker last week.

This is not theoretical. In the last month of auditing vibe-coded apps, we have found hallucinated packages, abandoned dependencies with critical CVEs, and malicious typosquats sitting in production lockfiles. The AI does not check any of this. It optimises for "code that runs."

How AI tools choose packages

When you ask an AI to "add a date picker" or "integrate Stripe", it picks a library based on training data patterns. It does not check:

  • Whether the package is actively maintained

  • Whether the version it picks has known vulnerabilities

  • Whether the package name matches what is actually on npm (hallucination)

  • Whether transitive dependencies introduce risk

  • Whether the licence is compatible with your project

The AI sees "date-fns is popular for dates" and writes import { format } from 'date-fns'. It does not know that your project already has dayjs two folders up, or that the version it assumes is three major releases behind.

The hallucination problem

Large language models invent package names that sound right. A researcher demonstrated this by uploading empty packages with hallucinated names to npm — names like @types/react-router-dom (the real package is react-router-dom with types built in) or lodash-es-utils (does not exist, but sounds like it should). Within days, AI-generated code started importing them.

If your AI imports a package that does not exist on npm, the build fails. That is the safe outcome. The dangerous outcome is when a similarly named package does exist, uploaded by someone waiting for exactly this mistake.

Test this: search your lockfile for any package name you do not recognise. Run npm view <package-name> --json and check the maintainers, time.modified, and repository fields. If the repository is missing or points to an empty GitHub org, treat it as suspicious.

Outdated versions with known CVEs

AI training data has a cutoff. The model suggests versions that were current when it was trained. Meanwhile, the ecosystem moves on.

A common pattern: the AI writes "axios": "^0.27.0" in package.json. The current version is 1.7.x. Version 0.27 has a known SSRF vulnerability (CVE-2023-45857). The AI does not know this. It only knows the pattern axios.get(url) works.

We see this with:

  • lodash < 4.17.21 (prototype pollution)

  • moment (deprecated, no security updates)

  • request (deprecated, multiple CVEs)

  • ua-parser-js < 1.0.0 (supply chain compromise in 2022)

  • event-stream (the original supply chain attack — the AI still suggests it for streaming)

Test this: run npm audit or pnpm audit on your project. Do not ignore the moderate and high findings. If a vulnerability sits in a transitive dependency, you still ship it.

Transitive dependency chains

You install chart.js. It pulls in chart.js dependencies. One of those pulls in another. Ten levels down, a package maintained by one person in their spare time gets compromised.

The AI does not trace this chain. It sees the top-level import and assumes the ecosystem handles the rest.

Test this: run npm ls <suspicious-package> to see the full dependency path. If a vulnerable package sits five levels deep, you own the risk.

A practical audit you can run in ten minutes

1. Generate a software bill of materials

Run cyclonedx-bom -o bom.xml (or use pnpm sbom / npm sbom if available). This gives you a machine-readable list of every package, version, and licence. Feed it to a vulnerability scanner like grype or trivy.

2. Check for hallucinated or suspicious packages

Open package-lock.json or pnpm-lock.yaml. Search for:

  • Package names you did not explicitly add

  • Packages with no repository field

  • Packages last updated more than two years ago

  • Packages with a single maintainer and no organisation

3. Run npm audit --audit-level=high

Fix everything at high or critical. For moderate findings, check whether the vulnerable code path is actually reachable in your app. If you cannot confirm it is not reachable, update the package.

4. Verify top-level dependencies are intentional

Run npm ls --depth=0 --prod (or pnpm ls --depth=0 --prod). Every package listed should be one you or your team chose. If the AI added something, verify it is the right tool for the job — not just the first one the model recalled.

5. Pin versions in your lockfile

Do not rely on ^ or ~ ranges for production deploys. Commit the lockfile. Use npm ci (or pnpm install --frozen-lockfile) in CI so the exact versions you audited are what deploy.

What the free surface check sees

The free surface check scans what is publicly visible on your deployed app. It does not read your lockfile or your node_modules. It can flag client-side bundles that expose package names or versions in source maps, but it cannot audit your dependency tree.

For a full dependency audit, the launch-readiness audit includes a supply chain review: we scan your lockfile, check every package against vulnerability databases, verify maintenance status, and flag hallucinated or typosquatted names. You get a must-fix list with the exact package, version, CVE, and the upgrade command.

The habit that prevents this

Add a pre-commit hook that runs npm audit --audit-level=high. Add a CI step that fails the build on new high or critical vulnerabilities. Schedule a monthly npm outdated review.

Better: treat every AI-suggested package as a pull request you would review. Read the README. Check the GitHub issues for recent security activity. Confirm the version is current. Then accept it.

The AI writes code fast. The dependency review is the part that cannot be fast.


Want a developer to check your dependency tree? The launch-readiness audit covers 137 points across 14 areas, including a full supply chain review. You get a launch-readiness score, a ranked must-fix list, and a call to walk through every finding.

Want a developer to look at your app?

Built your app with AI tools? Run the free surface check yourself in a few minutes. Nothing to buy, and we never look at your app unless you run it.