AI-generated code security is the problem nobody budgets for until it is too late. A founder launched Moltbook, a social network for AI agents, after saying publicly that he “didn’t write a single line of code” for it. Days later, Wiz researchers found a Supabase API key in the site’s client-side JavaScript with no Row Level Security behind it. Anyone holding that key could read and write the entire production database.

This is not a hypothetical. Wiz’s write-up of the Moltbook breach lists 1.5 million API authentication tokens, about 35,000 email addresses and thousands of private messages exposed. The team locked it down within about three hours of Wiz’s report on January 31, 2026. The founder knew how to ship. Nobody had checked what the AI left open. The full story is in the Moltbook vibe coding security breakdown.

The actual numbers on AI code security in 2026

The statistics are uncomfortable to sit with, especially if you have been shipping AI-generated code without a consistent review process:

  • 45% of coding tasks produced OWASP Top 10 vulnerabilities — Veracode’s 2025 GenAI Code Security Report, 80 tasks across more than 100 models
  • 56% average security pass rate in Veracode’s July 2026 update, barely changed from 55% a year earlier
  • 86% and 88% failure rates on cross-site scripting and log injection, per Veracode
  • 35 new CVEs in March 2026 traced to AI-generated code, up from six in January and 15 in February — Georgia Tech Vibe Security Radar
  • 322% more privilege escalation paths at a Fortune 50 company after AI assistant adoption — Apiiro, cited by the Cloud Security Alliance
  • 400+ leaked secrets found in a scan of 1,400 vibe-coded apps — Escape.tech, cited by the Cloud Security Alliance
  • Up to 2.74x more security issues in AI-co-authored pull requests than human-only ones — CodeRabbit’s analysis of 470 PRs

The Cloud Security Alliance’s research note on the AI-generated CVE surge adds a warning about undercounting: the Georgia Tech researchers estimate the true number of AI-caused CVEs is 5 to 10 times what they can confirm. A significant share of AI code is going to production without the review passes that slow down but genuinely protect human-written code.

The pattern I keep seeing: teams adopt AI tools, their output velocity jumps, code review gets shorter because “the AI wrote it cleanly,” and the security pass gets skipped because the code looks fine. It usually does look fine. The vulnerability is in the part that is not on the screen.

Why AI code is structurally insecure

This is the part nobody in the AI tooling marketing wants to talk about plainly: AI models optimise for plausible correctness, not resistance to adversarial input.

When you ask an LLM to write authentication middleware, it produces code that correctly handles the expected inputs — a valid token, a well-formed request, a user who exists. It does not produce code that instinctively hardens against the inputs that do not fit the happy path: the null session that gets evaluated to truthy, the token that passes expiry checks because the timezone offset was ignored, the admin role check that gets bypassed on endpoints the AI did not know were sensitive.

Veracode ran a direct test: 80 code completion tasks, each with a known chance to introduce a CWE weakness, given to more than 100 models. The models picked the insecure implementation in 45% of cases. Java was worst, failing more than 70% of the time. Veracode’s CTO summed it up: “GenAI models make the wrong choices nearly half the time, and it’s not improving.” The insecure option is often shorter, more conventional, and closer to what is overrepresented in the code that gets written about, published and indexed.

A senior engineer reading AI-generated authentication code immediately looks at the edge cases because they have been burned by those edge cases before. A junior engineer — or a non-engineer founder — reads the same code, sees that it handles valid inputs correctly, and ships it. The bug that surfaces at 3am six months later was always there.

CVE-2025-53773: when the AI tool itself becomes the vector

The API key leak above is a developer mistake amplified by AI. CVE-2025-53773 is something more unsettling: the AI coding tool itself as the attack surface.

Published on August 12, 2025, CVE-2025-53773 is a CVSS 7.8 command injection flaw in GitHub Copilot and Visual Studio. Johann Rehberger’s write-up shows how it worked. Instructions hidden in content Copilot reads, such as a source file, a web page or a GitHub issue, told the agent to add "chat.tools.autoApprove": true to a VS Code settings file. That switched Copilot into what Rehberger calls “YOLO mode”, with every confirmation turned off, and the injected instructions could then run terminal commands on the developer’s machine. Microsoft fixed it in the August 2025 Patch Tuesday release.

This is indirect prompt injection, and it is the attack the OWASP Top 10 for LLM Applications lists as LLM01, the top risk for LLM applications. The attack does not come from your prompts. It comes from content the AI was asked to read: a code comment, an issue, a database entry, a web page in a RAG pipeline.

The CVE-2025-53773 example is not an edge case. It is the mechanism playing out in a real, widely used tool, and the same pattern of agents rewriting their own config files is now a supply chain technique, as the Claude Code hooks guide explains.

OWASP Top 10 for LLM Applications 2025: what changed for agentic systems

OWASP’s 2025 edition of the Top 10 for LLM Applications reflects exactly how production AI usage shifted. The first edition was written with standalone chatbots in mind. The 2025 edition is written for what most developers are actually building: agentic systems with tool access, RAG pipelines, and multi-model orchestration.

The updated top 10 covers prompt injection, sensitive information disclosure, supply chain vulnerabilities, data and model poisoning, improper output handling, excessive agency, system prompt leakage, vector and embedding weaknesses, misinformation, and unbounded consumption.

Three of these deserve specific attention for developers writing agentic code, as covered in the agentic coding guide:

Excessive agency (LLM06): This is the permission scope problem. If your AI agent can write to a database, it should only have write access to the specific tables it needs. Most agentic scaffolding gives agents broad permissions because it is easier to set up. The blast radius when something goes wrong is the entire scope of permissions granted — not just the feature you intended.

Improper output handling (LLM05): AI output goes somewhere. If it goes into a database query, you need parameterisation. If it goes into HTML, you need encoding. If it goes into a shell command, you need sandboxing. AI-generated code that handles its own output has a tendency to skip these steps because the training data skipped them too.

Supply chain vulnerabilities (LLM03): AI models fabricate package names that sound plausible but do not exist, then use them in generated code. A USENIX Security 2025 study cited by the Cloud Security Alliance found about 20% of 576,000 generated code samples referenced packages that did not exist, and 43% of those names came back on similar prompts. Attackers register them. Every dependency in AI-generated code needs verification.

The security checklist for AI-generated code

This is not a full security audit. It is a first pass — the things that catch the most common failures in the least time:

Before it merges:

Run the diff through Semgrep with the OWASP ruleset. Free, open source, takes 30 seconds on most PRs. It catches hardcoded secrets, injection vulnerabilities, insecure deserialization, and the most common OWASP Top-10 failures automatically. I have had it catch hardcoded credentials in AI-generated code three times in four months.

Check every external API call in the diff. AI models sometimes fabricate API endpoints that do not exist — using outdated training data to construct URLs that look right but point nowhere or, worse, to domains that get registered by third parties. Verify any API base URL you did not write yourself.

Review permission scopes explicitly. If the feature adds a database query, confirm the DB role used has minimum required permissions. If it adds a new API route, confirm authentication middleware is applied and not just assumed.

For agentic code specifically:

Apply the principle of least privilege to every tool the agent can call. An agent that needs to read a calendar does not need write access to the calendar. An agent that queries a database does not need schema modification rights. This is basic IAM applied to AI — it is not being applied by default.

Validate inputs before they reach the model and outputs before they leave. Indirect prompt injection (CVE-2025-53773 style) is easier to execute when the model has no input filtering. Output filtering catches cases where the model has been manipulated into producing something it should not.

Log what the agent does, not just what it was asked to do. Agentic AI introduces a new kind of opacity — the model takes intermediate steps that are not always visible. Without logging at the tool-call level, post-incident analysis becomes guesswork.

The correction rule from experience:

When I find a security issue in AI-generated code, I look for the same pattern in everything the same model wrote in the same session. AI models are consistent in their mistakes — if it hardcoded a credential once, it probably did it again somewhere nearby. Same goes for permission scopes: one over-permissioned role usually means every role in that session is over-permissioned.

The honest account of vibe coding’s security debt

The vibe coding in production post on this blog covers the productivity reality: AI-generated code produces 1.7x more issues than human-written code, and senior developers are the ones who benefit most because they have the judgment to review the output. That post covers the productivity side honestly.

The security dimension is a separate problem. Productivity issues surface in QA. Security issues surface in breach reports.

The developers I have spoken to who are doing this well share one practice: they treat AI-generated code the way a senior engineer treats code from a capable but inexperienced colleague. Fast, often good, needs a real review before it ships. The review is not optional and it is not shorter because the AI wrote it — if anything, it is longer, because the code is unfamiliar.

The ones who are not doing well have let the velocity of AI code generation compress their review process. The code ships fast, it looks clean, it passes basic tests. The vulnerabilities do not announce themselves.

Models choosing the insecure option in 45% of Veracode’s tasks, with almost no improvement in a year, is a number that should stop people. It has not stopped everyone, because nobody finds out until something goes wrong. Set up the review pass before something goes wrong.


Statistics from: Veracode 2025 and 2026 GenAI Code Security Reports, Cloud Security Alliance AI-Generated CVE Surge research note (April 2026), Georgia Tech Vibe Security Radar, Wiz, OWASP Top 10 for LLM Applications 2025. CVE-2025-53773 details from Tenable’s CVE database and Embrace The Red.

(Updated October 10, 2026: corrected the opening breach story, which was the Moltbook database exposure documented by Wiz, not a SaaS case from the Cloud Security Alliance; corrected CVE-2025-53773 from CVSS 9.6 to 7.8 and from a pull-request-description attack disclosed in 2026 to a prompt injection that enabled auto-approval, published and fixed in August 2025; corrected the description of Veracode’s study, which tested 80 tasks across 100+ models rather than 4 million scans or six models; removed statistics attributed to a “Sherlock Forensics 2026” report and unsourced 60%, 44%, 46% and 73% figures that could not be verified; re-attributed the 2.74x figure to CodeRabbit’s pull request analysis, where it describes security issues rather than overall vulnerability density; and added Veracode’s 2026 update, Apiiro, Escape.tech and USENIX figures.)