vibe-audit.workshop

guides · 2026-10-11

7 Security Mistakes AI Coders Keep Making

AI coding assistants are trained on the entire public internet — including millions of lines of insecure code. So they don't just write code fast; they reproduce the internet's worst security habits at machine speed. Here are the seven vulnerability patterns that show up again and again in AI-generated code, and what to do about each one.

1. SQL injection via string concatenation

The classic never dies. Ask an AI to "write a login query" and there's a good chance you get f"SELECT * FROM users WHERE name = '{username}'" — user input stitched straight into SQL. One quote character in the input and your database is an open book. The fix is older than the AI: parameterized queries or an ORM, every time, no exceptions. Any code review checklist for AI-generated code should start here.

2. Cross-site scripting (XSS) in rendered output

AI-generated frontends love innerHTML and template literals: el.innerHTML = `<div>${userInput}</div>`. If userInput contains a <script> tag, congratulations — you've shipped stored XSS. The fix: use text-content APIs or a framework that escapes by default, and treat every innerHTML in generated code as guilty until proven innocent.

3. Hardcoded secrets and API keys

Models trained on tutorials — where keys are pasted inline "for simplicity" — happily emit const API_KEY = "sk-live-..." in client-side code. Client-side secrets aren't secrets; they're public strings. Keys belong in server-side environment variables, rotated the moment they've touched a repo or a chat log. This is the single most common finding in AI-generated codebases we see.

4. Missing authentication and authorization checks

"Build me a dashboard with an admin page" often yields routes with no auth middleware at all — or authentication without authorization, so any logged-in user can hit admin endpoints. AI models optimize for the happy path; the access-control matrix is your job. Every generated route needs an explicit answer to: who can call this, and what are they allowed to touch?

5. Insecure direct object references (IDOR)

/api/orders/{orderId} that returns any order ID you ask for, without checking it belongs to you. AI-generated APIs routinely skip the ownership check because the prompt never mentioned multi-tenancy. Test every parameterized endpoint with another user's ID — it's the cheapest security test that exists.

6. Weak cryptography and randomness

MD5 for password hashing, Math.random() for tokens, homegrown "encryption" with XOR — the training data is full of these, so the models repeat them confidently. Passwords need argon2 or bcrypt; tokens need a CSPRNG; encryption needs a vetted library, never hand-rolled. Treat any crypto in generated code as a red flag until verified.

7. Hallucinated dependencies

The newest and nastiest pattern: the model invents a package name that doesn't exist — pip install arctic-auth-utils — and attackers register that exact name with malware inside. It's called slopsquatting, and it's a supply-chain attack the AI sets up for you. Verify every dependency against the real registry before installing; if a package has zero history, treat it as hostile.

Why these patterns persist

These aren't bugs in any one model — they're statistical echoes. The models predict the most likely next token, and the most likely code on the internet is average code, written under deadline, without a security review. "Most likely" and "secure" are different distributions. Prompting helps ("use parameterized queries", "no hardcoded secrets") but doesn't eliminate the problem: studies of AI-generated code consistently find vulnerability rates that demand human review.

A review workflow that works

  1. Constrain the prompt: name your security requirements explicitly — parameterized queries, escaped output, env-based secrets, auth on every route.
  2. Scan automatically: run every AI-generated change through a security scanner before merge. Vibe-Code Audit checks for exposed secrets, injection flaws, XSS patterns and missing headers with copy-paste fixes.
  3. Verify dependencies: check every package name against npm/PyPI; flag anything newborn or hallucinated.
  4. Review the seams: humans review auth logic, crypto choices and data flow — the things scanners approximate and models fumble.

AI writes the first draft fast. Security is the editing pass you never skip.


Informational explainer, not a security guarantee. Scan your code free before every deploy.

← all guides