Risk · R-068 · Model & Application Security
Insecure AI-generated code
Code suggested by an AI assistant is accepted with vulnerabilities, invented dependencies or licence problems that review would have caught in code a person wrote.
- Severity
- High
- Audience
- Heads-of · Practitioner
- Frameworks
- Principle 9 · AML.T0060 · LLM10
- Responsible AI domain
- Lifecycle stage
- Reviewed
- 2026-11-10
What it is
Coding assistants produce plausible code quickly. Plausible is not the same as secure: generated code can omit validation, use weak cryptography, mishandle errors or reference a package that does not exist. The risk is in acceptance. Developers review generated code less closely than their own, and the volume produced can outrun the organisation's capacity to review. Code that an agent writes and runs itself is covered in unexpected code execution by agents.
How it happens
- A suggestion containing a known weakness is accepted because it works.
- The assistant names a package that does not exist, and an attacker registers it.
- Generated code reproduces licensed material without its licence.
- Large generated changes are approved on the strength of passing tests.
Why it matters
The defects are ordinary software vulnerabilities with ordinary consequences. What changes is the rate at which they are introduced and the erosion of the review that used to catch them.
Warning signs
- Review time per change falls as change size rises.
- New dependencies appear that no one chose.
- Security scan findings rise in step with assistant adoption.
- No policy says where assistants may be used.
Who owns it
The head of engineering is accountable for code quality whatever its origin. Security sets the scanning and review standard. Teams remain responsible for every line they merge.
In practice
A developer asks an assistant for a function that imports customer records from a file. The suggested code builds a database statement by joining strings. It passes the tests and is merged; the import endpoint is later found open to injection. The same pattern generalises to any team that treats generated code as already reviewed.
Mitigating controls
Primary controls
- Review of AI-generated code Detective
- Puts generated code through the same review, scanning and dependency checks as any other code. Code produced with an AI assistant passes the same human review, security scanning and dependency checks as any other code before it is merged.
Supporting controls
- AI acceptable use policy Directive
- Sets where code assistants may be used and with what checks. A policy approved by top management states what AI use is permitted, what is prohibited, what every system must pass through, who is accountable, and where to take a case the policy does not settle.
- AI bill of materials Detective
- Dependency records expose invented or unvetted packages. The models, datasets, libraries, tools and hosted components that make up each AI system are recorded and checked against known vulnerabilities, licence terms and supplier changes.
- Role-based AI training Directive
- Developers learn what assistants typically get wrong. Reviewers, developers, risk and assurance staff, approvers and front-line teams receive training specific to their AI responsibilities, with competence assessed and completion tracked.
Framework and clause references
| Framework | Clause | Title |
|---|---|---|
| Code of Practice for the Cyber Security of AI | Principle 9 | Conduct appropriate testing and evaluation Testing and evaluation before release. |
| MITRE ATLAS | AML.T0060 | Publish Hallucinated Entities Invented package names that attackers then register. |
| OWASP Top 10 for LLM Applications | LLM10 | Improper Output Handling Generated code is output that must be handled as untrusted. |
Sources
- OWASP Top 10 for LLM Applications OWASP GenAI Security Project · framework
- MITRE ATLAS MITRE · framework
Related terms
How to cite
Axiom Verity (2026). Insecure AI-generated code. Reference Library, R-068. https://axiom-verity.com/risks/insecure-ai-generated-code. Reviewed 2026-11-10.
Found an error or a better source? Report a correction.