AI code security: how to test AI-generated code before it ships

AI code security: how to test AI-generated code before it ships

More of this quarter’s pull requests came from Cursor, Copilot or Claude Code agents, and your reviewers read diffs for logic and style while a generated route that skips an ownership check sails through. Carnegie Mellon’s SusVibes benchmark put numbers on where AI code security breaks down, with 57% of the best agent setup’s solutions working and only 11.8% secure. Escape’s scan of more than 5,600 public vibe-coded apps points the same way: nearly 60% had critical security flaws, driven mainly by misconfigured permissions rather than injection. The flaws that matter most in AI-generated code are the ones a repository scanner was never built to find, and catching them means testing the running app as a second user.

What is AI code security?

AI code security is the practice of finding and fixing vulnerabilities in code written by AI assistants and agents, and in vibe-coded apps, before that code reaches production. It covers two layers. One is the code itself, where the risks are exposed secrets, injection, and bad dependencies. The other is how the deployed app behaves once real users hit it, which is where authorization gaps and open database rules live.

AI-generated code needs its own testing routine because agents produce working features faster than people can review them, and a feature that passes its functional test can still be exploitable.

Vibe coding security applies the same discipline to apps built mostly by prompting, often by people without a security background, on platforms such as Lovable, Bolt and Base44. To secure AI-generated code in either setting, you test both layers before every release.

Escape runs the runtime layer of that check continuously. Cascade 2 Iguazu, its multi-agent AI pentesting engine, attacks the app as more than one user, returns exploitable findings with complete reasoning logs, and learns from past pentest and bug bounty reports to create tailored attack paths specific to an applications' weaknesses.

AI-generated code vulnerabilities to test for

The flaws that show up most often in AI-generated code map to the OWASP Top 10:2025 classes, making them easier to triage and assign. Each class needs its own test.

Six flaws that AI writes, and how to catch them

Missing authorization, IDOR and weak authentication

A prompt usually describes what an endpoint should return and rarely says who’s allowed to call it, so generated routes often ship with no ownership check at all. OWASP files that under A01 Broken Access Control in the Top 10:2025.

IDOR follows when a generated query filters on the ID in the request and nothing else, and OWASP’s API Security Top 10 ranks that flaw first as broken object level authorization.

Georgia Tech’s Vibe Security Radar lists authorization bypass among 74 confirmed CVEs that researchers traced to AI coding tools by April 2026, and 14 of them are rated critical.

Escape’s scan of public vibe-coded apps turned up 12 confirmed BOLA findings and 2 zero-click account takeovers, along with more than 400 exposed public state-altering endpoints.

Generated login flows also tend to skip controls nobody asked for, such as login rate limits, single-use reset tokens, JWT signature checks, and error messages that don’t reveal which accounts exist.

Each of these flaws passes a demo run from a single account because that account only ever asks for its own data. The test that exposes them has to log in as a second user and request the first user’s records.

Open database rules and exposed secrets

Vibe-coded apps commonly pair a generated frontend with a backend-as-a-service such as Supabase, whose publishable key (the legacy anon key) is designed to ship in the browser.

Because that key is public, the protection rests on row level security. Supabase’s docs state that a table in an exposed schema without RLS is readable and writable by any role with a grant on it.

In Escape’s scan, every token exposed by default was an anon token, which is meant to be public. The exposure came from missing or weak RLS policies, not from the key, and the scan found no JWT configuration flaws.

NVD records CVE-2025-48757 as an insufficient RLS policy in Lovable-generated sites that let unauthenticated attackers read or write database tables, and the supplier disputes the finding.

Escape’s scan found the same weakness still shipping: it reports 2 confirmed CVE-2025-48757 cases, where unauthenticated reads of backend tables exposed stored GitHub App secrets and short-lived tokens. In one verified case, an unauthenticated GET request carrying only the public anon key returned names, birth dates, bank account details and a plaintext password for several users.

In the Moltbook case, Wiz Research found 1.5 million API authentication tokens and 35,000 email addresses exposed through a misconfigured Supabase database. Wiz reached that database with a key taken from client-side JavaScript.

Hardcoded API keys and service-role keys also land in source files and git history (CWE-798). Deleting the line later leaves the value in every clone, so a committed key stays exposed until it’s rotated. Escape’s scan found 400+ leaked secrets in public vibe-coded apps, including 6 GitHub tokens, 7 OpenAI API keys and 2 admin payment API keys, and traces most of them to privileged credentials embedded in frontend bundles or database policies that were never configured.

Injection, SSRF and missing rate limits

String-built SQL queries, unencoded HTML output and eval on user input still appear in generated code, and they fall under A05 Injection in the OWASP Top 10:2025. Georgia Tech’s researchers name server-side request forgery among the AI-traced CVEs alongside authorization bypass.

SSRF appears when generated server code fetches a URL the user supplied. Without an allowlist on the destination, that request can hit the cloud metadata endpoint at 169.254.169.254 and pull instance credentials, or reach internal services that assume the caller is already inside the network. Escape’s scan confirmed 4 SSRF cases, where supplying a callback URL as an input parameter made the target service request it.

Missing rate limits get less attention because nobody prompts for them. An unthrottled login form becomes a brute-force target, and an unthrottled LLM-backed endpoint lets anyone run up your model bill.

Verbose errors leak in the same way. Escape logged more than 600 server errors and exposed stack traces across its sample, mostly triggered by passive crawling and often carrying file paths, library versions or debug endpoints.

Hallucinated packages and outdated dependencies

Across 576,000 generated code samples, a USENIX Security 2025 study found that at least 5.2% of package references from commercial models and 21.7% from open-source models named packages that didn’t exist. The researchers counted 205,474 unique hallucinated names.

Registering one of those names before anyone else is called slopsquatting, and the attacker’s package then gets installed by anyone who trusts the suggestion.

Models also suggest library versions that were common in their training data, and those older versions can carry known CVEs. OWASP tracks the risk as A03 Software Supply Chain Failures in the 2025 list.

Escape found the same exposure in deployed vibe-coded apps: 254 instances of JavaScript libraries with known CVEs in unauthenticated, public-facing assets. The report ties it to dependencies inherited from platform templates, where one outdated library version can spread across hundreds of deployments.

Coding tools sit in the supply chain as well, as Cursor’s CVE-2025-54135 showed when an indirect prompt injection wrote an MCP configuration file and reached remote code execution.

Vibe coding security risks that only show up at runtime

Open database tables and cross-user data access live in places a code scanner never reads. A passing CI pipeline says nothing about them, because the test that catches them has to run against the deployed app.

What each test can see

What code scanners catch in AI-generated code

Static application security testing (SAST), secret scanning and dependency analysis read the repository. That makes them reliable at flagging hardcoded keys, string-built queries, eval calls and packages that are known to be vulnerable or don’t exist at all.

They’re also cheap enough to run on every commit, which the Cloud Security Alliance recommends for AI-assisted development alongside human review of authentication, cryptography and input-handling code.

Adding instructions to the prompt helps less than you’d hope, since Carnegie Mellon’s SusVibes researchers found that vulnerability hints in the request couldn’t mitigate the security issues.

What only a test against the running app proves

Authorization between users, row-level security policies, and rate limits are properties of the deployed system. A code scanner has no second user to log in as, and the database policy usually lives in the Supabase or Firebase project, outside the repository the scanner reads.

The Moltbook exposure fits that pattern, since Wiz noted that the client-side Supabase key was expected by design and traced the danger to the backend configuration the key pointed to.

Escape’s researchers assessed more than 5,600 apps and found 34,232 vulnerabilities, nearly 2,000 of them high-impact, plus 400+ exposed secrets and 175 PII exposures across publicly available vibe-coded apps. Most of those flaws were reachable without authentication, and Escape notes that its passive, non-destructive scans make the numbers a lower bound.

In that data, misconfigured permissions, not injection, were the primary cause, particularly Supabase RLS policies that LLMs struggle to configure correctly. Escape also logged 98 highly critical issues it traces to wrong coding practices in AI-generated code.

Because the same model tends to reproduce the same mistake across projects, a flaw confirmed in one app is worth retesting everywhere the same tool wrote code.

How to secure AI-generated code with an AI code security audit

Run this audit before every release that ships generated code. The map keeps the scan from missing endpoints an agent added without telling anyone, and the retest keeps a later prompt from quietly regenerating a flaw you already removed.

AI code security audit

Map what the AI built and exposed

The audit starts with an inventory of what was generated, including routes, API endpoints, frontend bundles, backend-as-a-service projects and any MCP servers an agent added. Endpoints and keys referenced in client JavaScript belong on that list, because that’s where Escape’s researchers found anonymous tokens tied to Supabase APIs in vibe-coded apps.

Escape’s report also suggests searching your network traffic for vibe-coding platform domains such as .lovable.app and .base44.com, and asking teams which customer-facing apps were built with AI tools.

Recording which code an AI tool produced helps you scope the review, and the CSA recommends extending your SBOM to capture AI tool provenance. Attack surface management tooling can keep the inventory current as agents add endpoints between audits.

The inventory also sets the test accounts the runtime step needs, one per role, so the second-user test has real users to work with.

Scan every pull request

Secret scanning has to cover the full git history as well as the current tree, because a key deleted in a later commit is still in the history. SAST rules for string-built queries, eval, disabled JWT verification and routes without auth middleware catch the code-level half of the flaw list.

Software composition analysis handles dependencies, and every new package gets two checks. It has to exist and be the one you meant, since hallucinated package names are an active supply chain risk, and OSV-Scanner has to find no known vulnerability for it in OSV.

Code that touches authentication, authorization, cryptography or input validation also gets a human reviewer, as the CSA recommends for AI-assisted work.

Test the running app as two users

Run an authenticated dynamic scan of staging with one account per role, and check whether user A can read or change user B’s data. That cross-account check is how IDOR surfaces, and Escape’s multi-user testing examples walk through the pattern.

Escape’s Cascade 2 Iguazu runs this test as an AI pentest. Give it more than one account and it attacks staging as each, then files a finding only after it reproduces the exploit, with the request sequence and the user scopes involved.

For apps on Supabase, send an unauthenticated request carrying only the publishable (or legacy anon) key and see whether any table returns data to an unauthenticated caller. Supabase’s Security Advisor flags misconfigured RLS policies, so run it after every schema change.

Rate limits, SSRF, and verbose errors get checked the same way, by sending the requests an attacker would send, in volume and with crafted URLs. A scoped scan that blocks the merge request, plus a full scan after deployment, keeps the runtime test in step with how fast an agent ships.

Each fixed finding then gets retested against the running app, and the request that proved it stays on as a regression test so a later prompt can’t bring the flaw back. In Escape, every diff in code and everything it affects is pentested on every merge, deploy, or on a schedule. So as AI-generated code is injected, its effects are verified as soon as the code is pushed.

Vibe coding security checklist

Run this gate on any app built mostly by prompting, confirming each check against the running app wherever you can.

  • Every key is out of source, client bundles, and git history, and any key that was ever committed has been rotated.
  • Every table in an exposed schema has RLS enabled with a policy, confirmed by an anonymous request against the live API.
  • Every route that returns user data checks ownership, confirmed by a second-account test.
  • Every new dependency exists, is the intended package, and has no known vulnerability in OSV.
  • Login, signup, password reset, and AI-backed endpoints are rate-limited, and error messages don’t reveal whether an account exists.
  • Every finding that was proven once reruns as a regression test on every build, not only at release.

Best AI code security tools by testing type

AI code security tools fall into five layers, from rules that steer the agent before it writes to AI pentests that prove an exploit against the running app. The top AI code security tools each cover one layer and miss what the one above it catches.

AI code security testing tools by type

Coding guardrails and code scanners

Cisco built Project CodeGuard, which the Coalition for Secure AI (CoSAI) now hosts, to give Cursor, Copilot, Codex, and Claude Code secure-by-default rules to follow while generating code. Cisco states that the rules don’t guarantee any given output is secure, which makes guardrails the first layer, with tests behind them.

On the scanning side, SAST rules run in the pull request and are cheap enough for every commit. gitleaks finds committed credentials across the git history, and OSV-Scanner checks every dependency against the OSV vulnerability database.

None of these tools logs in as a second user, so authorization and database-policy flaws stay outside their view.

Runtime testing for the running app

Dynamic application security testing (DAST) sends real requests to the running app and judges what comes back. ZAP (Zed Attack Proxy) is a free, open-source dynamic scanner with automation options for CI pipelines.

It fires its requests from a single identity, though, so it can’t answer the question that matters most with generated code, whether user A can reach user B’s data. That check needs two logged-in identities, and ZAP scans as one.

For apps on Supabase, the built-in Security Advisor flags tables exposed without row-level security, which makes it the quickest check of the database layer before a full scan.

Escape’s DAST tests business logic for BOLA, IDOR and access control flaws, reaching them through OAuth, SAML or TOTP MFA logins. Running from CI/CD, it can gate merge requests on its findings.

Its multi-user testing checks whether users with different roles can access each other’s data, automating the second-user test from the audit.

Escape runs DAST as the per-build half of its continuous testing. Cascade 2 Iguazu supplies the depth in the next layer, and every exploit it proves becomes a DAST regression test that runs on every build.

AI pentesting for proof of exploit

AI pentesting tools chain multi-step attacks against the running app and report each finding with the request sequence and response that leaked the data. An engineer can reproduce it with curl before touching the code, instead of debating whether it is real.

Escape’s Cascade 2 Iguazu attacks the running application with coordinated agents and files a finding only after it reproduces the exploit with its own proof.

Iguazu, the second version of Cascade, puts a scheduler in charge of each run. The scheduler works from a shared coverage map, decides which surface gets which agent, and records why each surface was closed, so two runs on the same app are comparable and a finding that disappears is more likely a fix than a detour. Reasoning logs show, for each finding, how the agent found the surface, what it tried and how the reviewer reached its verdict. On Escape’s internal benchmark, Iguazu covered 5.3× more API surface and 3.4× more application pages and states than the first version, and found 41% more critical issues.

For AI-written code, the point is cadence. Escape’s Continuous AI Pentesting runs Cascade on every merge, deploy or schedule and tests what each release changes, so a flaw an agent regenerates meets a pentest on the build that ships it. Cascade can also start from your repository in whitebox mode, available on request, and every finding is still proven against the running app.

Any Escape finding can be sent to Cursor, Codex or Claude as a prompt that carries the evidence and remediation guidance. An engineer still reviews the diff the agent produces.

How to choose AI code security solutions for your team

Which of the top AI-generated code security tools fits your team comes down to how much you ship and where your data lives.

  • A small AppSec team that owns more repositories than it can review gets the most from SAST, secrets and dependency checks in every pull request, plus one dynamic gate on staging.
  • Apps on Supabase or Firebase need an anonymous-access check and an RLS review after every schema change, whatever else the stack includes.
  • Multi-tenant apps need a tool that tests as several users at once, since a single-account scan can’t see cross-user access.
  • Teams shipping AI code daily need proven findings rerun as regression tests on every build, because a yearly audit only checks the version of the app that existed during the test window. Continuous AI pentesting covers that gap.

Conclusion

Agents will keep shipping faster than anyone can review, and the flaws that matter most stay invisible until someone logs in as a second user and reaches another user’s data. A code scan cannot see that, and a once-a-year pentest only covers the version it tested. Escape’s scan of public vibe-coded apps shows the cost of skipping it: 400+ exposed secrets and 175 PII exposures, with most flaws reachable without authentication. The check that keeps pace runs on every build, drives the app as more than one user, and proves each exploit before filing it. Escape’s Continuous AI Pentesting is that check: Cascade 2 Iguazu attacks what each release changes on every merge, deploy or schedule, and every exploit it proves reruns as a DAST regression test on every build.

FAQs

Which vendors test AI-generated code and vibe-coded apps for security flaws before release?

Escape tests AI-generated code and vibe-coded apps continuously. Cascade 2 Iguazu, its multi-agent AI pentesting engine, attacks the running app as more than one user and reproduces each exploit as proof before filing a finding. Most teams pair that with open-source code scanning in every pull request.

Is AI-generated code secure?

AI-generated code is not secure by default. Carnegie Mellon’s SusVibes benchmark found only 11.8% of the best agent setup’s solutions secure, even though 57% worked. It can ship safely once it passes code scanning, a runtime test and human review of authentication and cryptography code.

How common are security flaws in vibe-coded apps?

In Escape’s assessment of more than 5,600 publicly available vibe-coded apps, nearly 60% had critical security flaws. The scan found 34,232 vulnerabilities, 400+ exposed secrets and 175 PII exposures, and the primary cause was misconfigured permissions, especially Supabase RLS policies, rather than injection. Escape ran passive, non-destructive scans, so the figures are a lower bound.

How do you secure AI-generated code?

Map what the AI built, scan every pull request for secrets, injection and bad packages, test the running app as two users, then retest every fix as a regression test.

What is continuous AI pentesting for AI-generated code?

Continuous AI pentesting runs agent-driven attacks against the running app on every merge, deploy or schedule instead of once a year, and reruns each proven exploit as a regression test.

Can SAST find vulnerabilities in AI-generated code?

SAST catches the code-level flaws, and secret scanning, software composition analysis and a registry check cover exposed secrets, vulnerable dependencies, and hallucinated packages. It cannot find authorization gaps between users or open database rules, which live in the running system and its configuration, outside the repository.

What is slopsquatting?

Slopsquatting is when an attacker registers a package name that AI models hallucinate, so anyone who installs the suggestion pulls the attacker’s package. A USENIX Security 2025 study found at least 5.2% of package references from commercial models and 21.7% from open-source models named packages that did not exist.

Do security prompts make AI-generated code safe?

Security prompts help only at the margin. SusVibes found that vulnerability hints in the request could not mitigate the issues, and Cisco says its Project CodeGuard rules do not guarantee secure output, so a test still has to follow.

Sources

Introducing Cascade 2 Iguazu: multi-agent AI pentesting you can audit - Escape