Veracode tested 100+ AI models. 45% of their code flunked security, and smarter models didn't help.
- Date
- Jul 2025
- Tools involved
- Impact
- 45% of AI-generated code samples across 100+ LLMs introduced OWASP Top 10 vulnerabilities; XSS was defended in only about 14% of relevant cases
- Root cause
- Models got better at producing code that runs, not code that resists attack; security pass rates stayed flat across model generations
What happened
In its 2025 GenAI Code Security Report, released mid-2025, Veracode evaluated code produced by more than 100 large language models across Java, JavaScript, Python, and C#. The test battery used standardized coding tasks designed to invite known weaknesses, then checked whether the models walked into them. They did: 45% of generated code samples failed security testing by introducing vulnerabilities from the OWASP Top 10.
The failures clustered in specific places. AI models failed to defend against cross-site scripting (CWE-80) in about 86% of relevant samples, making XSS the sharpest weak spot in the report. Java was the riskiest language, with roughly a 72% security-failure rate across generated samples.
The most uncomfortable finding was the trend line. Between 2023 and 2025, models' syntactic pass rates climbed from around 50% to 95%. Over the same period, security pass rates stayed essentially flat, hovering around 45 to 55% regardless of model generation. Newer, more capable models wrote code that worked more often but was no more secure than what their predecessors produced.
A Spring 2026 Veracode follow-up reported the pattern persisting. The study has become the quantified backbone of the vibe-coding-risk conversation: AI is confidently shipping insecure code at scale, and raw capability gains alone are not closing the security gap.
Impact
There is no single breach to point at here, which is exactly why the number matters. A 45% security-failure rate across more than 100 models means that roughly half of all unreviewed AI-generated code carries a known, catalogued vulnerability class. For the worst cases, the odds are worse than a coin flip: an 86% failure rate on XSS defenses and a 72% failure rate for Java code mean that certain kinds of AI-generated code should be presumed vulnerable until a scan proves otherwise. Every app built by accepting suggestions without review inherits those odds.
Root cause
The models are optimized for producing code that works, and by that measure they improved dramatically: syntactic correctness went from about 50% to 95% in two years. Security is a different skill, and the report shows it is decoupled from capability. Security pass rates stayed flat around 45 to 55% across model generations, which means the training that made models better at shipping working code did nothing to make that code safer. Vulnerable patterns are well represented in what models learned from, and nothing in the generation loop flags them.
How to not be this entry
- Run static analysis on every AI-generated change before it merges. Treat "it compiles and the tests pass" as unrelated to "it is secure," because per Veracode's data, it is. Read the fix guide: SQL injection and XSS in AI-generated code
- Assume output encoding and input sanitization are missing until you have verified them. XSS was the report's weakest area, with defenses missing in about 86% of relevant samples.
- Review every AI-generated endpoint for authentication and authorization before it goes live. Insecure defaults ship silently. Read the fix guide: No auth on your AI-generated API endpoints: anyone can call your backend
- Do not relax your review bar when you upgrade models. Security pass rates were flat across generations, so a newer model earns exactly zero extra trust.
Tools that actually fix this
Recommended because they address the failure mode above, not because of the payout. Some are affiliate links; see how we choose.
Snyk Code catches injection and XSS right in your editor, and Snyk Open Source flags vulnerable and malicious packages. It covers several AI-code failure modes at once and is free for open source.
Try Snyk →All-in-one appsec (code scanning, dependencies, secret detection, containers) with low-noise output, built for small teams that cannot run five separate tools. One dashboard covers several failure modes.
Try Aikido Security →Frequently asked questions
What did Veracode's 2025 GenAI Code Security Report find?
Veracode's 2025 GenAI Code Security Report found that 45% of code samples generated by more than 100 large language models failed security testing by introducing OWASP Top 10 vulnerabilities. The evaluation covered Java, JavaScript, Python, and C# using standardized tasks designed to invite known weaknesses. The failure rate held steady even as models became far better at producing syntactically correct code.
Are newer AI models writing more secure code?
No. Veracode found that while syntactic pass rates climbed from about 50% to 95% between 2023 and 2025, security pass rates stayed essentially flat, hovering around 45 to 55% regardless of model generation. Newer models write code that works more often, but it is no more secure, and a Spring 2026 follow-up reported the same pattern persisting.
Which language and vulnerability class did AI models handle worst?
Java was the riskiest language in Veracode's 2025 report, with roughly a 72% security-failure rate for AI-generated samples. The single worst vulnerability class was cross-site scripting (CWE-80), where AI models failed to include defenses in about 86% of relevant samples.
Does the Veracode report mean you should not use AI coding tools?
The report does not say to stop using AI coding tools; it says to stop trusting their output unreviewed. With 45% of AI-generated samples introducing OWASP Top 10 vulnerabilities, the practical takeaway is to treat AI code like an untrusted contribution: run security scanning on every change, review authentication and input handling by hand, and never equate working code with safe code.
Sources
- Veracode: 2025 GenAI Code Security Report announcement
- Help Net Security: AI-generated code creates security risks in 45% of cases
- Veracode: 2025 GenAI Code Security Report (full PDF)
Related error guides
SQL injection and XSS in AI-generated code
No auth on your AI-generated API endpoints: anyone can call your backend
Wildcard CORS: Access-Control-Allow-Origin * in your AI-generated backend
Accidentally committed an API key to GitHub
The Vibe Oops briefing
One email when something ships to production that should not have. New incidents, new error guides, no filler.