Is AI-generated code secure?
Is AI-generated code secure? Often it isn't. Code from Cursor, Claude Code or Lovable can run fine and still let strangers read your data. AI assistants optimize for code that works, and nobody asked them to resist attackers. Here's what the research found, the five problems we see most, and a self-check you can run on your own repo.
QUICK CHECKLIST
- Search the repo and git history for keys
- Call every API route while logged out
- Try to read another user's data with a second account
- Look for SQL built from strings
- Ask your AI for a security review, then verify it
Is AI-generated code secure? What the research says
Veracode's 2025 GenAI Code Security Report tested more than 100 models on coding tasks in Java, Python, C# and JavaScript. In 45% of the samples, the generated code introduced a vulnerability from the OWASP Top 10. Java failed 72% of the time, JavaScript 43% and Python 38%. Cross-site scripting was the weak spot: the models failed to defend against it in 86% of the relevant samples.
Newer and bigger models wrote more code that compiled, but their security pass rate stayed flat. A better model won't fix this on its own.
5 AI-generated code security risks we see most
- Hardcoded secrets. API keys pasted into source files or sent to the browser. See leaked API keys and public env vars.
- Missing auth checks. Routes and server actions that work for anyone, logged in or not.
- Weak database rules. Supabase tables without RLS or with policies that let any account delete any row.
- Injection. User input glued into SQL queries or shell commands.
- Client-side trust. Prices, roles or limits checked only in the browser, or read from fields the user can edit, like Supabase user_metadata.
Quick self-check
Search for secrets
Search the repo for
sk-,api_key,secretandservice_role. Run gitleaks to cover git history too.Call your routes logged out
For each API route ask: what happens if a logged-out user calls this? Try it with
curland no cookie.Use a second account
Sign up twice. With account B, try to read, edit and delete account A's records by changing ids in requests.
Look for string-built queries
Search for SQL built with template strings or
+. Use parameterized queries or your ORM instead.Ask your AI, then verify
Paste the prompt below. Treat its answer as a list of places to check, and confirm each one yourself.
For the full list, run the vibe coding security checklist.
Act as a security reviewer for this repo. List every API route and server action without an auth check, every query built from strings, every secret in code or in a public env var, and every place a role, price or plan is trusted from the client. Give file and line for each.
Why AI code vulnerabilities slip through
Your assistant only sees what you asked for. If you never said "make it secure", it usually won't add rate limits, auth or input validation on its own. When something fails with a permission error, the quickest fix it finds is often to loosen the permission. It can also suggest packages that don't exist, which attackers exploit through slopsquatting.
Further reading
- Veracode: 2025 GenAI Code Security Report
- OWASP: Secure Coding with AI Cheat Sheet
- Leakcade: Vibe coding security checklist
FAQ
Is code from Cursor or Claude Code safe to ship?
It can be, after you review it. The tools write code that runs, and security checks often show up only when you ask for them. Check auth, database rules and secrets before you launch.
Can I just ask the AI to make my code secure?
It helps. A security review prompt finds real problems, but the AI can also miss things or invent findings. Use its answer as a list to verify, and test the important paths yourself with a logged-out browser and a second account.
Are newer AI models more secure?
Not by much. Veracode found that security pass rates stayed flat across model size and release date, even as the code got better at compiling.
Do I need a professional security audit?
If your app handles payments, health data or other people's personal data, yes. An automated check like Leakcade is a fast first pass. It doesn't replace a human audit or a pentest.
Want a second pair of eyes?
We review your whole repo and write a fix prompt for every finding. $19, report within an hour.
Check my repoLeakcade is an automated check. It can miss vulnerabilities and is not a substitute for a professional security audit or pentest. Provided as is. You stay responsible for your code. Where the law allows, our liability is limited to what you paid ($19). Terms