AI-Generated Code Security
The practice of finding and fixing vulnerabilities in code written by large language models and coding agents, before and after that code reaches production.
What is AI-generated code security?
AI-generated code security covers the risks introduced when large language models (LLMs), coding assistants, or autonomous coding agents write application code, and the controls used to catch those risks. Generated code can carry the same flaws as human-written code, such as injection, broken access control, and weak cryptography, plus problems specific to AI, such as hallucinated dependencies and insecure defaults repeated from training data. Securing it means reviewing, scanning, and testing both the code and the running application as you would any untrusted contribution.
No single standards body owns the topic. Practitioners describe the flaws with existing taxonomies, mainly the Common Weakness Enumeration (CWE) and the OWASP Top 10, whose current edition is the OWASP Top 10:2025. An early systematic measurement came from Asleep at the Keyboard?, a study accepted at the 2022 IEEE Symposium on Security and Privacy: Of 1,689 programs that GitHub Copilot produced for 89 scenarios, roughly 40% were vulnerable.
What is vibe coding?
Vibe coding is building software by prompting an AI model and accepting what it produces without reading or reviewing the code. Andrej Karpathy coined the term in a post on X in February 2025, describing a style in which the developer gives in to the vibes and can “forget that the code even exists,” as quoted by Simon Willison. Karpathy framed it as suitable for throwaway weekend projects. Willison draws the line at review: If a developer reads, tests, and can explain the code an LLM wrote, that is not vibe coding but software development.
The security problem appears when vibe-coded applications go to production with real users and data. Two 2025 incidents show both sides of it: a flaw in generated applications and a failure of the coding agent itself. In the first case, CVE-2025-48757 records that insufficient Row-Level Security policies in sites generated by Lovable versions through April 15, 2025, let unauthenticated attackers read or write arbitrary database tables. It is classed as CWE-863 (Incorrect Authorization), scored 9.3 under CVSS v3.1, and disputed by the supplier, which holds that customers are responsible for their own data. Semafor reported that, according to a report by a Replit employee, 170 of 1,645 Lovable-built apps examined exposed user information, including email addresses, financial details, and API keys.
In the second case, The Register reported in July 2025 that the Replit coding agent deleted the SaaStr founder’s production database despite instructions not to change code without permission, and then generated fictional records. This is a case of excessive agency in an AI agent with write access to production.
The Vibe coding security: The gap between “It works” and “It’s safe” post covers these risks and how to address them in more depth.
Common weaknesses in AI-generated code
The hallucinated-dependency problem is specific to AI. The study We Have a Package for You!, accepted at USENIX Security 2025, generated 576,000 code samples with 16 models and found an average hallucinated-package rate of at least 5.2% for commercial models and 21.7% for open-source models, with 205,474 unique invented package names. An attacker who registers one of those names in a public registry can get code execution on machines that install it. Package hallucination is one form of AI hallucination.
What current research shows
Veracode tests code from a set of models on fixed tasks and checks the output for selected CWEs. Its October 2026 update covered 18 models across Python, C#, JavaScript, and Java, tested against four CWEs. The average security pass rate rose to 62%, from 56% in the previous report, so 38% of results still contained a vulnerability. Results by weakness were uneven: Pass rates were 84% for SQL injection (CWE-89) and 87% for cryptographic weaknesses (CWE-327), but 18% for cross-site scripting (XSS, CWE-80) and 13% for log injection (CWE-117). Java passed in 31% of cases.
These figures come from the vendor press release; the full report holds the task methodology, which the release does not describe. The benchmark also measures single snippets, so it cannot show flaws that appear only when components interact, such as an authorization check placed in one service and skipped in another.
Why flaws in AI-generated code are easy to miss
Generated code usually compiles, passes the tests the model also wrote, and looks idiomatic, so it attracts less review than an obviously rough draft. Volume adds to this: A coding agent can produce changes faster than a team can read them. The most serious API flaws are often absent from the code entirely. A missing ownership check, an unprotected admin route, or a skipped approval step leaves no suspicious line for a static analyzer to flag, which is why application security testing of AI-built software needs a dynamic component that exercises the running application as different users.
How to test AI-generated code
- Treat generated code as an untrusted contribution: Require human review for authentication, authorization, cryptography, and data access code.
- Run static application security testing (SAST) and secret scanning on every change, and check that each imported package exists, is the intended one, and is pinned to a known version.
- Generate a software bill of materials (SBOM) for AI-built applications so hallucinated or outdated dependencies are visible.
- Test the deployed application dynamically with at least two user accounts and one unauthenticated session, requesting each other’s objects to expose BOLA and missing database policies.
- Fuzz inputs that reach queries, templates, and logs, since XSS and log injection remain the weakest categories in the Veracode data.
- Limit coding agents to non-production credentials and require approval for destructive operations.
- Retest after every regeneration, since a model can reintroduce a fixed flaw when it rewrites a file, which makes continuous penetration testing a better fit than an annual test.
These checks belong early in the pipeline, in line with shift-left practice, and again against the running application before release.
Testing AI-generated code with Equixly
Equixly runs AI penetration testing against web applications, APIs, LLM applications, and MCP servers. Its attacks target the live application, so the test covers the deployed behavior whether a person or a model wrote the code. The engine validates the outcome of each attack during the test. Equixly also integrates testing into CI/CD pipelines, so applications that change frequently, as AI-assisted projects tend to, can be retested on each change. The Equixly for Developers post describes the developer workflow.
More terms
View the glossaryAPI Security
The discipline of protecting application programming interfaces from unauthorized access, exploitation, and abuse, covering authentication, authorization, data exposure, and business logic across every endpoint an application exposes.
Autonomous Exploitation
The ability of an AI system to identify a weakness, plan an attack path, execute it, and confirm impact without a human directing each step, separating an adversary that reasons from a tool that runs a script.
BOLA (Broken Object Level Authorization)
The most consistently exploited API vulnerability - occurring when an application fails to verify that the user requesting an object actually has the right to access it, allowing attackers to enumerate identifiers and retrieve data belonging to other users without ever bypassing authentication.


