vibe-coding · 7 min read

Vibe Coding Security: 7 Risks in AI-Generated Code and Fixes

The security holes that show up most in apps built with AI coding tools: exposed keys, open databases, client-side auth, injection, hallucinated packages and unverified webhooks, with a fix for each.

Published

Reading time

7 min

Written by

KavioWeb

Cover: security risks in AI-generated code and how to fix them

The core vibe coding security problem: AI coding tools write code that works far more reliably than code that is secure. In Veracode's 2025 GenAI Code Security Report, which tested more than 100 language models on 80 coding tasks, the generated code introduced an OWASP Top 10 vulnerability in 45 percent of cases. The most common holes in vibe-coded apps are predictable: secret keys shipped to the browser, databases without access rules, auth enforced only on the client, missing ownership checks in APIs, injection, and dependencies that do not exist or should not be trusted. Each one has a straightforward fix.

Diagram: where AI-built apps usually leak, from browser bundle to API to database

Why vibe coding produces insecure code

It is not that the models do not know about security. Ask one directly and it will explain SQL injection well. The problem is the default path:

  • Prompts describe features, not threats. "Let users edit their profile" gets you an edit form, not a check that the profile belongs to the user.

  • The code is judged by whether it runs. A demo works fine with the database wide open.

  • Models copy common patterns, and a lot of public example code is insecure or written for tutorials.

Veracode also found that when a model could choose between a secure and an insecure way to write the same code, it picked the insecure one 45 percent of the time, and that security results had not improved as models got better at writing correct code.

1. Secret keys in the browser or in git

What it looks like: a Stripe secret key, OpenAI key or Supabase service_role key in a front-end file, a NEXT_PUBLIC_ or VITE_ variable, or a committed .env.

Why it matters: anything in your JavaScript bundle is public. Anything ever pushed to git should be treated as leaked. GitHub's guidance says removing the secret, pushing a new commit, or even recreating the repository does not stop it from being exploited.

Fix: revoke and rotate the key at the provider, move it to server-side environment variables, add .env to .gitignore, and turn on secret scanning and push protection in your repository.

2. Database open to anyone with the public key

What it looks like: a Supabase or Firebase app where the browser talks to the database directly and no access rules exist.

Why it matters: Supabase's docs state that a table in an exposed schema without Row Level Security is readable and writable by any role with a grant on it. Your anon key is in the browser by design, so without RLS anyone can query or modify every row.

Fix: enable RLS on every exposed table and add policies that tie rows to auth.uid(). For Firebase, write security rules instead of leaving test mode on. Then test as a second user: you should not be able to read the first user's data.

3. Auth that only exists in the UI

What it looks like: admin pages hidden by an if (user.isAdmin) in React, but the API behind them answers anyone.

Why it matters: an attacker does not use your UI. They call your API directly.

Fix: OWASP's authorization guidance is to deny by default and validate permissions on every request, on the server. Every protected route and API handler checks the session and the role before doing anything.

4. Missing ownership checks (IDOR)

What it looks like: GET /api/invoices/123 returns invoice 123 to any signed-in user, so changing the number shows someone else's invoice.

Fix: every query that loads a record by ID also filters by the current user or organisation: WHERE id = $1 AND owner_id = $2. It is easy to miss because it never shows up in a demo with one user.

5. Injection and unsafe HTML

What it looks like: SQL built with string concatenation, user input passed to a shell command, or user content rendered with dangerouslySetInnerHTML or innerHTML.

Why it matters: Veracode reported that models failed to defend against cross-site scripting in 86 percent of relevant cases and log injection in 88 percent.

Fix: use parameterised queries or an ORM, never build shell commands from input, and render user content as text. If you must render HTML, sanitise it with a maintained library.

6. Hallucinated or risky packages

What it looks like: the AI imports a package that sounds right but does not exist, or is a near-copy of a popular name.

Why it matters: attackers register those invented names. A 2024 study of 16 code-generating models found hallucinated package names in at least 5.2 percent of recommendations from commercial models and 21.7 percent from open-source models, with over 205,000 unique invented names.

Fix: before installing a package an AI suggested, check it on npm or PyPI: real repository, real maintainers, real download history. Commit your lockfile and run npm audit or an equivalent.

7. Trusting the client for money

What it looks like: the app marks an order as paid when the user lands on /success, or reads the price from the request body.

Fix: prices come from your server or the payment provider, and paid status changes only on a verified webhook from the provider.

8. No rate limits

What it looks like: login, sign-up, password reset and any AI endpoint accept unlimited requests.

Why it matters: brute-force attempts, spam accounts and, for AI features, a surprise bill from your model provider.

Fix: rate-limit auth and AI routes by IP and by account, cap tokens per request, and set a monthly spend limit at your AI provider.

A 30-minute self-audit

Check

How

Pass if

Keys in bundle

Search built JS for sk_, service_role, secret

Nothing found

Keys in history

Run a secret scanner over git history

Nothing found, or rotated

Database rules

Query another user's rows as user B

Empty result

Server auth

Call an admin API without a session

401 or 403

Ownership

Change an ID in a URL

404 or 403

Payments

Visit /success without paying

Nothing changes

Dependencies

Check each unfamiliar package on the registry

Real, maintained

For the rest of the launch work (backups, monitoring, domain), see the vibe-coded app production checklist.

FAQ

Is AI-generated code less secure than human code?

Studies like Veracode's show AI-generated code frequently contains well-known vulnerabilities, and that security has not improved as models improved at writing working code. Human code has bugs too; the difference is that AI produces a lot of code quickly, and people tend to review it less.

Can I ask the AI to make my code secure?

It helps to ask for specific things, such as "add RLS policies so users only read their own rows" or "use parameterised queries here". Then verify each fix by testing it. A general "make it secure" prompt tends to give confident answers without real changes.

What is the most dangerous mistake in vibe-coded apps?

An exposed database: a Supabase or Firebase backend with no access rules, so anyone with the public key can read or change all data. It is common, easy to exploit and easy to fix.

Do I need a security audit before launch?

If you store personal data, take payments or have business customers, a review by someone who did not write the code is worth it. At minimum, run the 30-minute self-audit above and fix everything that fails.

How do I check if my API keys leaked?

Search your deployed JavaScript and your full git history for key prefixes, and enable your repository's secret scanning. If a key was ever exposed, rotate it; deleting it from the code is not enough.

Want an expert review?

Kavio reviews and fixes AI-built apps: secrets, database policies, auth, payments and the rest of the list above, with a written report you can act on. See our services or get in touch.

Sources

  1. Veracode 2025 GenAI Code Security Report (press release)
  2. Spracklen et al., package hallucinations by code-generating LLMs
  3. Supabase: Row Level Security
  4. GitHub: Remediating a leaked secret
  5. OWASP Authorization Cheat Sheet

Next article

All articles →
Cover: Claude Code vs Cursor vs GitHub Copilot comparison

ai-coding-tools · 6 min read

Claude Code vs Cursor vs GitHub Copilot (November 2026)

Claude Code, Cursor and GitHub Copilot compared for vibe coders and freelancers: how each works, what the plans cost after Cursor joined the X Subscription, and which fits your workflow.

Read next ↗