VibeSecCheck
Home/Security Guides/ai-generated-code-vulnerabilities
High RiskAI Builders & StacksAI SecurityCursorClaude CodeCopilot

The 8 Most Common AI-Generated Code Vulnerabilities

LLMs trained on millions of StackOverflow snippets and hackathon repos systematically repeat the same 8 security anti-patterns unless explicitly constrained.

Why AI Builders Introduce This

Training data is skewed heavily toward quick tutorials that omit authentication, disable SSL verification, use wildcard CORS, and leave database authorization 'as an exercise for the reader'.

Real-World Exploit Impact
  • Broken Object Level Authorization (IDOR) in 1 out of 3 AI-scaffolded CRUD endpoints
  • Hallucinated or outdated packages and weak JWT verification (jwt.decode instead of jwt.verify)
  • Missing cryptographic signature checks on payment and auth webhooks

Vulnerable Pattern vs. Production Fix

Classic LLM Mistake: jwt.decode() Instead of jwt.verify()typescript
// VULNERABLE: jwt.decode does NOT verify the cryptographic signature!
import jwt from "jsonwebtoken";

const payload = jwt.decode(token) as { userId: string; role: string };
if (payload.role === "admin") {
  // Any attacker can forge a base64 token with role: "admin"!
}
Cryptographically Verified Token Check
// SECURE: Always verify signature, algorithm, and issuer
import jwt from "jsonwebtoken";

const payload = jwt.verify(token, process.env.JWT_SECRET!, {
  algorithms: ["HS256"],
}) as { sub: string; role: string };

if (payload.role !== "admin") {
  return Response.json({ error: "Forbidden" }, { status: 403 });
}

Copy-Paste AI Fix Prompt (Cursor · Lovable · Bolt · Claude Code)

Scan this entire codebase for the top AI-generated code vulnerabilities:
1. Replace any jwt.decode() used for auth decisions with jwt.verify() (or official Supabase/Auth.js session verification).
2. Check for SQL string interpolation, eval(), new Function(), child_process.exec() with user input, or dangerouslySetInnerHTML.
3. Verify every CRUD endpoint enforces resource ownership (IDOR prevention) on the server.
4. Check for hardcoded fallback secrets like process.env.JWT_SECRET || "dev-secret" and replace them with fail-fast startup checks.

How to Verify Your Fix Worked

  1. 1Grep for `|| "secret"`, `|| 'dev'`, `jwt.decode`, `dangerouslySetInnerHTML`, and `rejectUnauthorized: false`.
  2. 2Ensure every env secret fails loudly if missing instead of falling back to a hardcoded string.
  3. 3Run VibeSecCheck against your deployed build for external verification.

Frequently Asked Questions

Why do LLMs add `process.env.JWT_SECRET || 'secret'`?

To silence TypeScript 'string | undefined' errors and keep local dev running without a .env file. In production, a missing env var then silently uses the publicly known string `'secret'`!

Is Claude Code or Cursor safer than Lovable/Bolt?

All AI tools can generate vulnerable code if not prompted with security constraints. Security depends on your architecture guardrails, RLS policies, and pre-launch verification.

Does VibeSecCheck replace code review?

VibeSecCheck catches live surface leaks, headers, dotfiles, sourcemaps, and Supabase exposure instantly, and pairs with tailored AI Fix Prompts to guide deeper code-level fixes.

Related Security Playbooks