Security Vulnerabilities in AI Code
Last updated: 2026-11-045 min read
Sources checked 2026-11-0413 sourced figures
AI-generated code fails security tests at measured, stable rates: in Veracode’s 2025 tests of more than 100 LLMs, 45% of code samples introduced an OWASP Top 10 vulnerability, cross-site scripting went unprevented in 86% of relevant samples and Java samples failed at 72%. A re-run with newer models in October 2025 lifted only one provider’s models; the rest stayed in the band measured in July. The conclusion is uncomfortable and useful: the fix lives in the process around generation, not in waiting for better models.
Contents
The measured baseline
Veracode’s 2025 GenAI Code Security Report is a large public measurement of the question: more than 100 LLMs, four languages and 80 code-completion tasks with known potential for security vulnerabilities, scored by static analysis. The headline, 45% of code samples with an OWASP Top 10 vulnerability, matters less than two structural findings. Per language, the spread is wide: Java 72%, C# 45%, JavaScript 43%, Python 38%. And across model generations, functional quality improved while security performance stayed flat: in July 2025, newer and larger models bought no safety.
The re-run of the same benchmark in October 2025 has one exception: OpenAI’s GPT-5 passed 70% of the security tests and GPT-5 Mini slightly more, while most other models stayed in the 50% to 59% band measured in July, some lower. Cross-site scripting and log injection barely moved. One provider’s lead in one benchmark does not change the posture: whatever your model roadmap, the security work stays yours.
The recurring classes, and what catches each
| Measured exposure | Why generation produces it | Control, deterministic-first | |
|---|---|---|---|
| Cross-site scripting | Measured · 86% of relevant samples failed to prevent it (CWE-80)Veracode, GenAI Code Security Report · 2025 | Encoding depends on output context the model cannot seeEditorial defense mapping · 2026-11-04 | SAST rules + security criteria in the taskEditorial defense mapping · 2026-11-04 |
| Injection (SQL, command, log) | Highest measured · 88% of relevant samples failed to prevent log injection (CWE-117); no separate rate is published for SQL or command injectionVeracode, press release of 30 July 2025 · 2025 | String concatenation is the statistically common pattern in training dataEditorial defense mapping · 2026-11-04 | SAST, the classic reproducible catchEditorial defense mapping · 2026-11-04 |
| Hardcoded credentials | Advisory-flagged · BSI and ANSSI ask for a risk analysis of how secrets such as API keys are kept from leakingBSI and ANSSI, AI Coding Assistants · 2024 | Examples in training data hardcode; the model imitatesEditorial defense mapping · 2026-11-04 | Secret scanning pre-commit; secrets out of repos entirelyEditorial defense mapping · 2026-11-04 |
| Weak cryptography | Measured · over 85% of the cryptography tasks passed in the October 2025 re-run (CWE-327); the advisory still names MD5 password hashing as a typical suggestionVeracode, re-run of October 2025 · 2025 | Outdated algorithms are overrepresented in old public codeEditorial defense mapping · 2026-11-04 | SAST + dependency policies pinning approved primitivesEditorial defense mapping · 2026-11-04 |
| Missing authentication/authorization checks | Context-dependent · beyond a scanner's reach; BSI and ANSSI: generated code should be checked and reproduced by the developersBSI and ANSSI, AI Coding Assistants · 2024 | Trust boundaries are set in the architecture, not in the promptEditorial defense mapping · 2026-11-04 | Human review of trust boundaries; criteria per taskEditorial defense mapping · 2026-11-04 |
The mapping explains the flat-across-generations finding: the worst classes are the ones where security depends on context outside the generation window. Where output lands, what the trust boundary is, what the organization considers approved crypto. More parameters do not supply missing context. The general failure taxonomy behind this is in why AI code fails.
The defense stack, deterministic-first
- SAST and secret scanning per change. The pattern-shaped classes fall to deterministic tools, reproducibly and cheaply; the division of labor with static analysis is detailed in SonarQube vs. verification.
- Security criteria in the task. “Validates input per X, encodes output for Y, touches no auth paths”, written before the run, checkable after it. This is what supplies the context the model lacked.
- Human review at the trust boundaries. Relieved of the mechanical layer, review judges what no scanner can: whether the boundary itself is right.
- With the BSI/ANSSI baseline under it all: generated code is checked and reproduced by the developers before it is used. In Sonar’s 2026 survey, 48% of developers always check AI-assisted code before committing it. Our reading, not Sonar’s or Veracode’s: the two figures come from different samples and do not multiply, but where the other half of a team does not always check, the defect supply meets a gate that is not reliably closed. The metric that names it is the unverified-merge rate, counted on the changes that touch input, output or authentication.
Where Reality Graph fits
Reality Graph is not a security scanner and does not replace SAST. It covers the second layer of this stack: the security criteria are written into the task, Reality Graph checks the change against them in each run, and it records the outcome, skipped checks included, in an evidence report. Reality Graph runs the approved checks itself, so the record shows the exit code of each scan and a scan that never ran shows as not run. Scanners answer “does this code contain known-bad patterns?”; verification answers “did this change respect the security requirements we actually set?” Both, per change, is the posture the numbers argue for.
This analysis gives you
- The measured class-by-class picture, with study design named
- The flat-across-generations finding, its one exception and its consequence
- A defense stack ordered deterministic-first
- Language-level risk weighting for your stack
It does not give you
- A replacement for SAST: Reality Graph is not a scanner
- An argument against AI on sensitive code, only against unverified AI
- Exact rates for your codebase: measure with your own pipeline
- A model recommendation: one provider's lead in one benchmark re-run is not a control in your pipeline
FAQ
- Which security vulnerabilities does AI code produce most often?
- Veracode's July 2025 evaluation of more than 100 LLMs gives a measured picture. 45% of generated code samples introduced an OWASP Top 10 vulnerability overall. Two classes stood out: models failed to prevent log injection (CWE-117) in 88% of relevant samples and cross-site scripting (CWE-80) in 86%, and the October 2025 re-run left both nearly where they were. Weak cryptography did comparatively well, with over 85% of those tasks passing in October. The pattern is consistent: the classes where security depends on context the model does not see fail worst.
- Are newer, larger models more secure?
- Mostly no, and that is the report's most uncomfortable finding. In July 2025, functional correctness improved across model generations while security performance stayed flat regardless of model size or training sophistication. Veracode's October 2025 re-run found one exception, OpenAI's GPT-5 models at about 70% of security tests passed; most other models stayed in the 50% to 59% band of July, some lower. The practical consequence: waiting for the next model generation is not a security strategy. The fix belongs in the process around generation, in checks, criteria and gates, rather than in model selection.
- Why does AI keep producing these specific vulnerabilities?
- Three compounding reasons. Training data: models learned from decades of public code, much of it insecure, so the insecure pattern is often the statistically common one. Missing context: whether output encoding is needed depends on where data ends up, which the model often cannot see from the prompt. And objective mismatch: generation optimizes for code that works, and insecure code usually works, so the vulnerability is invisible to the 'does it run' test that implicitly guides generation.
- Does the programming language matter?
- Substantially, per the same evaluation: Java samples failed security tests at 72%, the worst of the four languages tested, against 38% for Python, 43% for JavaScript and 45% for C#. The exact ranking will shift with tasks and models, but the spread itself is the finding. Your risk profile depends on your stack, and a team's hardening effort should be weighted accordingly.
- What actually catches these vulnerability classes?
- A layered answer, deterministic-first: SAST and secret scanning catch the pattern-shaped classes (injection, hardcoded credentials, weak crypto) reproducibly and cheaply, which is where tools like SonarQube earn their place. Security acceptance criteria in the task catch the context-dependent classes the scanner cannot judge. And human review, relieved of the mechanical layer, judges the trust boundaries. No single layer covers the spread; the stack does.
- Should we stop using AI for security-sensitive code?
- The data supports a narrower conclusion: never merge AI-generated security-sensitive code on generation trust alone. Teams that write security requirements into the task (input validation, encoding, authentication paths as explicit criteria), run SAST per change and gate on human review use AI on sensitive code with measured rather than assumed risk. The 45% figure describes unverified output: it is an argument for the pipeline, not against the tool.
Keep reading
Sources
- Veracode – 2025 GenAI Code Security Report (30 July 2025): 100+ LLMs, 45% of code samples with an OWASP Top 10 flaw, XSS 86%, Java 72%, C# 45%, JavaScript 43%, Python 38%, security flat while functional quality rose; checked 4 November 2026
- Veracode – press release of 30 July 2025: 80 code-completion tasks, log injection (CWE-117) failed in 88% of cases; checked 4 November 2026
- Veracode – press release of 18 November 2025 on the October 2025 re-run: GPT-5 70% of security tests passed and GPT-5 Mini slightly more, most other models 50% to 59%, cryptography over 85% of tasks passing, XSS below 14% and log injection near 12% passing; checked 4 November 2026
- BSI and ANSSI – AI Coding Assistants (joint report, 4 October 2024): lack of output quality and security as a risk, generated code to be checked and reproduced by developers, secrets in the risk analysis; checked 4 November 2026
- Sonar – State of Code Developer Survey (press release, January 2026): 48% of developers always check AI-assisted code before committing it; checked 4 November 2026