Skip to content
CMU Research: Only 10% of AI-Generated Code Is Secure July 2026

CMU Research: Only 10% of AI-Generated Code Is Secure July 2026

Gecko Security12 min read
On this page

The cmu ai code study findings are pretty uncomfortable if your team leans on AI coding tools. 61% of generated code functions correctly. 10.5% passes security review. That means code can return the right values, handle expected inputs, and still contain an injection flaw or a missing access control check. We tend to treat test passage as a quality signal, but the CMU research shows that signal tells you almost nothing about what lives underneath.

TLDR:

  • The CMU study tested 80 coding tasks across 5 languages: 61% of AI-generated code works, only 10.5% passes security review
  • Functional code and secure code look identical in a diff; visual code review catches neither injection flaws nor broken access control
  • AI models train on correctness, not security, so access control logic, input validation, and trust boundaries are structurally undertested
  • Treat AI-generated commits as a distinct audit surface and run SAST before merge, not after
  • Gecko Security's contextual AI SAST traces access control gaps and injection paths across call chains, catching the semantic bugs pattern-matching misses

What the CMU Study Actually Measured#

The researchers behind this study didn't ask a simple question like "can AI write code?" They set up a controlled experiment across 80 coding tasks spanning five programming languages: Python, JavaScript, TypeScript, Java, and C. Each task was assigned to one of four popular AI coding tools, and the output was scored against two separate criteria: functional correctness and security.

The results split cleanly along those two dimensions. Roughly 60% of the generated code worked as intended. Only about 10% met a reasonable security standard.

That gap is the finding worth paying attention to. A piece of code can pass its test suite, return the right values, and handle the expected inputs, while simultaneously containing an exploitable vulnerability. Functional correctness and security are orthogonal properties, and AI models optimized for the former show little evidence of reasoning about the latter. Teams looking for a structured response should review securing AI-generated code before scaling these workflows.

What "Secure" Meant in This Context#

The study applied security evaluation criteria grounded in real vulnerability classes, not stylistic preferences. Reviewers assessed whether generated code introduced common weaknesses: injection flaws, insecure defaults, missing input validation, improper error handling, and related categories that appear consistently in production incident reports.

This is worth noting because "secure" in this context wasn't a moving target or a vague quality bar. The 10% figure reflects code that would survive scrutiny against known, documented vulnerability patterns, not a theoretical ideal.

Why the Study Period Matters#

The CMU study landed at an interesting moment in the AI coding tool cycle. By mid-2025, the developer tooling market had moved past early experimentation. GitHub Copilot had been generally available for three years. Cursor had grown into a widely adopted tool among professional developers. Claude and GPT-4 were being called inside CI pipelines and chat windows alike, part of a broader wave of best AI code security tools that teams were assessing for production use. Developers were no longer asking whether to use AI for code generation. They were asking how much of their workflow to hand over.

That context matters for interpreting the findings. A study showing 60% functional code and 10% secure code in 2022 would have been a footnote about immature tooling. The same numbers in 2025 describe production behavior at scale. Security teams reviewing pull requests, auditing repositories, and triaging findings are doing so against a backdrop where a large fraction of the code they see was written with AI assistance.

The study also arrived as regulatory and compliance pressure was building. The EU Cyber Resilience Act had moved into enforcement planning. NIST was updating secure software development guidance. Organizations were being asked to account for how their code was produced, and also whether it passed a scan, a question that touches core SAST vs DAST trade-offs that compliance teams were revisiting. A benchmark from a credible research institution gave security and engineering leadership a concrete reference point for those conversations.

The Velocity Boost Is Real but Short-Lived#

AI coding assistants do accelerate development. Studies show developers using GitHub Copilot complete tasks 26% faster on average. That speed gain is real, and teams feel it immediately.

The problem is that the gain compounds a hidden cost. When code ships faster, so do the bugs inside it. The CMU study found that 61% of AI-generated code ran correctly, which sounds acceptable until you look at the security layer: only 10.5% met basic security standards. Speed without correctness is just a faster way to accumulate debt.

The debt is not distributed evenly. The vulnerabilities that AI tools introduce at pace (missing input validation, broken access control logic, injection paths left open across generated functions) are the categories that take longest to remediate once they reach production. A developer who writes a feature in 26% less time and ships an authorization bypass in the same commit has not saved time. They have shifted the cost forward and compounded it with remediation effort, incident response, and the organizational drag of a security finding that surfaces weeks or months after the original commit.

The velocity illusion breaks down further when you account for review load. Security teams inherit the full output of AI-assisted development, including the fraction that compiles cleanly. A codebase growing 26% faster generates proportionally more surface area for static analysis, more findings to triage, and more manual review hours before any finding can be closed. The net throughput gain at the team level is narrower than the individual productivity numbers suggest, and in teams without tooling calibrated for AI-generated code, it can invert entirely.

60% of AI-Generated Features Work. Only 10% Are Secure#

The precise figures: 61% of AI-generated code functions correctly, while only 10.5% passes security review. Fewer than 11 out of every 100 generated snippets clear a basic security bar.

That gap traces back to training objectives. AI coding models are trained and scored on whether generated code runs and produces the right output, not on whether it handles edge cases, validates inputs, or enforces access controls. Correctness and security are different targets, and these models were only ever aimed at one of them.

Why AI Code Fails Security Reviews#

AI code generators produce output that looks correct. It compiles, passes tests, and ships. The security problems surface later, usually under conditions no unit test exercises.

The CMU research gives that pattern a number. Across the tasks studied, 60% of outputs functioned as intended. Only 10% cleared security review. The gap between those two figures is where real exposure lives.

Why Functional and Secure Diverge#

A few structural reasons explain the gap:

Failure ModeRoot CauseConsequence
Training objective mismatchLLMs optimize for outputs that match training patterns: code that runs, not code that resists abuse. Security properties rarely appear in training labels.The model has no direct signal to optimize against security; it is structurally blind to it.
Implicit input trustLLMs generate for the happy path because that is what training examples show. Validation, sanitization, and boundary checks require anticipating adversarial use.Generated code accepts untrusted input without sanitization, leaving injection paths open.
Context-blind authorizationWho is allowed to do what depends on the broader system, not the function in isolation. A model generating a single function cannot reason about trust boundaries it cannot see.Access control logic is produced without modeling the trust boundary being crossed.
Compressed error handlingGenerated code often silences exceptions or returns generic responses to satisfy functional requirements.Internal state is exposed to callers who should not see it, leaking information under failure conditions.
  • LLMs optimize for outputs that match training patterns, which skews toward code that runs instead of code that resists abuse. Security properties rarely appear in training labels, so the model has no direct signal to optimize against.
  • Generated code tends to trust its inputs. Validation, sanitization, and boundary checks require the author to anticipate adversarial use. LLMs generate for the happy path because that is what training examples show.
  • Authorization logic is contextual. Who is allowed to do what depends on the broader system, not the function in isolation. A model generating a single function cannot reason about trust boundaries it cannot see.
  • Error handling gets compressed. Generated code often silences exceptions or returns generic responses in ways that expose state to callers who should not see it.

The result is code where the functional requirements pass and the security requirements were never part of the specification the model was solving for.

Static Analysis Warnings and Code Complexity Keep Rising#

As AI coding tools accelerate development velocity, the volume of code reaching review and production keeps climbing. More code means more surface area, and the static analysis warnings that accompany it grow proportionally. Security teams that once triaged hundreds of findings per sprint now contend with thousands, many of them low-confidence flags that require manual investigation before anyone can act. This is a core limitation of static code analysis that becomes more acute as AI output volume grows.

Code complexity compounds the problem. AI-generated code tends toward verbose, deeply nested structures that satisfy functional requirements but obscure control flow. When a static analyzer encounters those patterns, it produces more warnings, not fewer, because the signal-to-noise ratio degrades as path counts increase.

The result is a backlog that grows faster than teams can clear it. Engineers deprioritize security review not from negligence but from arithmetic: there are more findings than hours, and the cost of investigating a false positive is identical to investigating a real one until someone does the work.

See it in action.

The Confidence-Reality Gap in AI-Assisted Development#

There is a measurable gap between how confidently developers ship AI-generated code and how secure that code actually is. When AI tools produce code that compiles, passes tests, and looks syntactically correct, developers tend to treat it as production-ready. The CMU study puts a number on why that assumption breaks down: roughly 60% of AI-generated code works as intended, but only about 10% meets security standards.

That gap matters because the failure mode is invisible at the surface level. Functional code and secure code look identical to a developer reviewing output from an AI coding assistant. The bugs that make code insecure are not syntax errors or obvious logic failures. They tend to be missing input validation, improper authentication checks, or subtle trust boundary violations that only surface under adversarial conditions.

Why Developers Extend Trust They Shouldn't#

Several patterns in developer behavior amplify the risk:

  • AI coding assistants generate output with high fluency and apparent correctness, which creates an implicit signal of quality. Developers trained to treat compilation and test passage as validation carry that habit into AI-assisted workflows without adjusting for what AI tools do not check.
  • Code review at speed favors catching what looks wrong, not what is absent. A missing authorization check leaves no visible artifact in the diff, which is exactly what Claude code review exposes that conventional scanners cannot tell you about real risk.
  • AI tools are trained on codebases that contain insecure patterns alongside secure ones. The model learns to reproduce what it has seen, and what it has seen is not a curated set of security-reviewed code. That gap is a supply-chain risk that extends to RCE in your test suite via attack vectors skill scanners miss.

The result is a class of ai code bugs that are structurally different from traditional developer errors. They are not random. They cluster around the exact conditions where AI code generation is weakest: access control logic, input handling, and any behavior that depends on context the model cannot see.

Limitations of the CMU Research#

The CMU study is valuable precisely because it is narrow. It tested AI-generated code written in response to specific prompts across a defined set of task types, which means its findings describe a controlled experimental environment, not the full range of production codebases where AI tools are used today.

A few constraints are worth keeping in mind when reading the results.

The study drew from a fixed pool of coding tasks. Real engineering work spans more varied contexts, including legacy system integrations, complex authorization schemes, and multi-service architectures where security properties are harder to assess against a single correctness standard.

The security evaluation methodology focused on identifiable vulnerability classes. Logic flaws and access control bugs that depend on application-specific business rules are harder to catch in automated assessment, which means the 10% security rate may overstate how secure AI-generated code is in practice.

The research also tested code at the point of generation, before any human review or iterative refinement. Developers who use AI coding tools rarely ship the first output unmodified, so the study captures a worst-case snapshot of what AI produces, not what actually gets deployed.

None of this invalidates the core finding. A 10% security rate under controlled conditions with well-formed prompts is a low ceiling. If anything, the limitations above suggest the real-world picture could be worse, not better.

What Development Teams Should Do With These Findings#

The CMU findings point toward three workflow adjustments for security-aware engineering teams.

  • Treat AI-generated code with the same scrutiny as hand-written code, or higher. A 10% security pass rate is not a baseline that warrants lighter review in the name of speed. The insecure output looks syntactically identical to the secure output inside a diff; no visual code review catches injection flaws or broken access control by appearance alone.
  • Run static analysis on AI-generated code before it merges. Pattern-based SAST will still miss logic flaws, a fundamental reason why static analysis struggles with business logic vulnerabilities, but it catches the low-hanging issues that show up repeatedly in the CMU sample: hardcoded credentials, unsafe deserialization, missing input validation.
  • Track AI-generated code as a distinct audit surface. If your team cannot separate AI-assisted commits from hand-written ones, you cannot measure whether the security posture of that subset is improving or degrading over time.

How Gecko Security Closes the AI Code Security Gap#

Gecko Security was built around the exact failure modes the CMU research exposes. Where AI coding assistants produce code that compiles and runs but skips input validation, mishandles authentication, or leaves injection vectors open, Gecko's contextual AI SAST reasons over a compiler-accurate semantic model of the codebase to find what those tools leave behind.

The CMU findings map directly to what Gecko catches: insecure cryptographic implementations, improper input handling, and broken access control patterns that appear functional at the surface but fail under adversarial conditions. Gecko traces these across call chains and service boundaries, extending beyond the file where the AI wrote the vulnerable line.

Why Static Pattern Matching Falls Short Here#

The core problem with reviewing AI-generated code using conventional SAST is a mismatch of approaches. AI assistants produce code that passes syntactic checks. The vulnerabilities that remain, the 90% that the CMU study found failing security standards, tend to be semantic: logic that is structurally valid but contextually wrong.

Gecko reasons over the full semantic graph instead of matching against rule sets. It can identify:

  • Authentication bypass conditions where AI-generated code follows the correct structural pattern but skips enforcement in specific code paths, a pattern covered in depth in the Claude code security review guide for developers
  • Injection vulnerabilities where untrusted input reaches a dangerous sink across multiple AI-generated functions that individually look clean
  • Access control gaps where the AI produced a working feature without modeling the trust boundary it was crossing

The result is that Gecko catches the category of bugs the CMU study found most common in AI-generated code, the ones that only appear when you trace execution across context instead of scanning line by line.

Final Thoughts on AI Code Bugs and What the CMU Research Actually Found#

The CMU study confirms what a careful code review already shows: AI-generated code that runs is not the same as AI-generated code that is safe. Your security posture right now depends on how you account for that gap across every AI-assisted commit in your codebase. Static analysis helps, but the bugs that matter most in AI-generated code are semantic, not syntactic. Talk to the Gecko team about what that distinction looks like in practice.

FAQ#

What did the CMU study actually find about AI-generated code security?#

The CMU study tested 80 coding tasks across five programming languages and found that 61% of AI-generated code functions correctly, while only 10.5% passes security review. The gap exists because AI coding models are trained to produce code that runs and returns correct output, not code that validates inputs, enforces access controls, or handles adversarial conditions.

Why does AI-generated code fail security reviews even when it passes tests?#

AI models generate for the happy path because that is what training examples show. The result is code that trusts its inputs, compresses error handling, and produces authorization logic without visibility into the trust boundaries of the broader system. A missing authorization check leaves no visible artifact in a diff, so functional testing and visual code review both miss it, the failure only surfaces under adversarial conditions.

How do I track AI-generated code as a distinct security audit surface?#

Separate AI-assisted commits from hand-written ones in your version control workflow so you can measure whether the security posture of that subset improves or degrades over time. Without that separation, you cannot tell whether your security controls are keeping pace with the volume of AI-generated code reaching production.

Is the 10% security rate from the CMU ai code security research likely to reflect real-world production code?#

The CMU study tested code at the point of generation before any human review or iterative refinement, making it a worst-case snapshot. The study also focused on identifiable vulnerability classes, meaning logic flaws tied to application-specific business rules, which are harder to catch in automated assessment, may not be fully counted. The real-world rate could be worse, not better.

Gecko Security

Frequently asked questions

Related content

The latest news, technologies, and resources from our team.

Subscribe to the Gecko newsletter

Occasional updates, new content, and insights. No spam; unsubscribe anytime.

We use your email only to send you our newsletter. See our privacy policy for how we handle your data. You can unsubscribe at any time.