Vulnerabilities in AI-Generated Code: What CTOs Need to Know
AI-generated code reproduces known vulnerability classes at scale. Here is what types appear most often, why LLMs produce them, and what to do about it.
AI-generated code introduces real, exploitable security vulnerabilities at scale. Large language models are trained on public code repositories where security was rarely the priority - Stack Overflow answers from 2012, open-source scaffolding with hardcoded credentials, API handlers that assume authorization at the route level. When an LLM generates code from those patterns, it reproduces the same mistakes. The result is not hypothetical risk. It is known vulnerability classes - IDOR, SQL injection, exposed keys, broken authentication - appearing in production code at a rate that scales with how fast teams are shipping.
What kinds of vulnerabilities appear most often in AI-generated code?
The same classes that have dominated breach reports for a decade, now reproduced faster and at greater volume:
/api/invoices/12345 returns any invoice for any logged-in user who knows the ID./admin and /api/admin endpoints.Why does AI-generated code reproduce security mistakes?
Three reasons, none of which are bugs that will be patched away:
- Training data is historically insecure. The public code an LLM learned from reflects the security culture of its era. Pre-2020 code has more injection vulnerabilities. Pre-2015 code has more authentication flaws. LLMs average over this entire history - they do not preferentially reproduce the most recent, most secure patterns.
- LLMs optimize for "works," not "secure." A generated snippet that passes the obvious test is a good snippet by the model's reward signal. There is no runtime adversarial signal in training. The model has no concept of what happens when a malicious user sends a crafted request.
- Context window does not cover the threat model. An LLM generating an API endpoint has no knowledge of the broader application's authorization structure, the data sensitivity of the objects being served, or the attack surface the endpoint is being added to. It makes locally reasonable decisions that are globally insecure.
How fast are these vulnerabilities being exploited?
Fast enough that a quarterly security review is not a meaningful control.
When exploitation is faster than most security review cycles, the only credible response is security that runs as continuously as the pipeline it is protecting. AI-generated code shipped on Monday is attack surface by Monday afternoon.
Is this different from vulnerabilities in human-written code?
Yes, in two important ways:
- Scale. A developer who makes a mistake makes it once, in one place. An LLM that produces a vulnerable pattern reproduces it everywhere that pattern is contextually appropriate. If the authorization check is missing in one endpoint, it is probably missing in all endpoints generated by the same model with the same prompt pattern.
- Opacity. Human-written code reflects the developer's mental model - there is a reason for every line, even if the reason is wrong. AI-generated code is statistically probable, not intentional. Reviewing it requires checking not just what the code does, but whether the implicit assumptions it encodes are correct - an expensive, manual process that most teams skip.
Does a SAST scanner catch these vulnerabilities?
Some of them, sometimes.
SAST scanners are trained on the same vulnerability classes and have the same problem as AI code generators: they flag patterns, not behaviors. A scanner catches the textbook SQL injection - string concatenation in a query builder. It does not catch the IDOR in an API endpoint that has perfectly valid code structure but missing authorization logic. Authorization flaws, business logic vulnerabilities, and context-dependent access control failures require an adversarial perspective - actually attempting to access objects you should not be able to access.
The output of a scanner on an AI-heavy codebase is typically 500-1,000 findings, most of which are false positives or low-severity informational items. The 3 critical findings that represent real breach risk are somewhere in that list. Finding them requires someone who can read the application the way an attacker would.
What should a startup do about vulnerabilities in AI-generated code?
First: acknowledge the baseline has changed. If your team is using AI code generation at scale (Cursor, GitHub Copilot, Claude in the IDE), your code is materially different from what a traditional security review was calibrated to evaluate. The review process needs to catch up.
Second: treat authorization as the highest-priority class. IDOR and broken access control are the most common and most damaging findings in AI-heavy codebases. Every API endpoint should have explicit authorization logic that is independently reviewed - not generated.
Third: run continuous offensive testing. The exploitation window is 4 hours. Point-in-time security (quarterly VAPT, annual pentest) was calibrated to a world where that window was 771 days. It is not calibrated to now. The only security posture that makes sense given the Zero Day Clock data is one that runs continuously - the same way the CI/CD pipeline does.
Fourth: demand proof, not flags. A scanner tells you what might be wrong. A finding worth fixing comes with the HTTP request that worked, the data it exposed, and reproduction steps. If your security process cannot show you an actual exploit, it cannot tell you what your real risk is.
Frequently asked
What percentage of AI-generated code contains security vulnerabilities?
Are newer LLMs (GPT-4o, Claude, Gemini) more secure than older ones?
Does a SAST scanner catch vulnerabilities in AI-generated code?
Is AI-generated code safe to use in production?
How is reviewing AI-generated code different from reviewing human-written code?
Does Greywatch specifically test for vulnerabilities in AI-generated code?
Greywatch finds the vulnerabilities that ship with AI-generated code. The harness runs continuously. A security engineer validates every finding. You get confirmed critical vulnerabilities - with exploit proof - not a thousand-item noise dump.
Start with a free scan →