# Securing AI-generated code: review, provenance and evidence

- Canonical: https://comonad.co.uk/guides/securing-ai-generated-code
- Source: Comonad Limited
- Published: 1 December 2026
- Last updated: 4 December 2026

**Definition.** An AI-enabled SDLC is a software delivery process where the use of AI assistants and agents is governed by policy, checked by quality gates and recorded for audit.

**In short**

Treat AI-generated code like any other code: the same security requirements, review and tests, with someone other than the person who asked the assistant approving the change. Keep the evidence, and look hardest at authentication, secrets, dependencies and pipeline files.

Hold AI-generated code to the same security requirements, review and tests as any other code, with one addition: the person who approves a change must not be the person who asked the assistant for it, and the assistant never counts as a reviewer. Then keep the evidence: which tool produced the change, what it was asked to do, which checks ran and who approved it. Put extra scrutiny on authentication, secrets, dependencies and pipeline files, because that is where a plausible mistake costs most.

_This is a working outline for engineering and security teams. It describes published guidance; it does not certify any process or product._

## What changes when an assistant writes the code, and what does not

Your security requirements do not change. The code still has to meet them, and the existing gates still apply. ENISA's draft [Technical Advisory on AI-assisted software development](https://www.enisa.europa.eu/sites/default/files/2026-09/ENISA%20Technical%20Advisory-AI-assisted-software-development-draft.pdf) (version 0.4, September 2026) puts the reason in one line: "functional correctness should not be confused with security." Code that compiles and passes its tests can still be insecure, and an assistant optimising for the task it was given will not always notice.

Three things do change. Volume goes up, so review time per line goes down unless you plan for it. The author is no longer one person who understood every line, so review has to be real rather than a formality. And the assistant reads things: issues, pull request comments, documentation, tool outputs. Any of those can carry instructions an attacker planted. The [OWASP Top 10 for LLM Applications](https://genai.owasp.org/llmrisk/llm01-prompt-injection/) puts prompt injection first for that reason.

ENISA's draft organises its advice into four actions: identify the lifecycle process and security expectations that apply, specify them for the assistant or agent, verify outputs through review, approval and security checks, and record the supporting evidence. The rest of this guide follows roughly that order.

## Review: who may approve

The OWASP AI Security Verification Standard, in [Appendix C on AI-assisted secure coding](https://github.com/OWASP/AISVS/blob/main/1.01/en/0x92-Appendix-C_AI_for_Code_Generation.md), makes this its first validation requirement. AC.4.1 says AI-generated code always goes through review by a qualified human engineer, that "the reviewer must not be the same identity that asked for the AI generation in the first place", and that "the AI agent itself does not count as the human reviewer."

The first rule matters more than it looks. A developer who prompted the change has already decided it is right. Asking them to approve it is asking for a second read by the same mind. The second rule closes the obvious shortcut of having one model review another and calling that sign-off. An automated reviewer can be a useful check. It is not an approver.

AISVS maps the requirement to [NIST SSDF](https://csrc.nist.gov/pubs/sp/800/218/final) practice PW.7, on reviewing and analysing human-readable code, and to segregation of duties in ISO/IEC 27001. The [SLSA v1.2 source track](https://slsa.dev/spec/v1.2/source-requirements) makes two-party review its highest source level. Neither was written for AI. Both fit it.

## Files that need a second person

Some files deserve a stricter rule whoever wrote them, and more so when an assistant did. AISVS AC.4.4 asks for an elevated review threshold, such as two-person review or security sign-off, for AI-generated changes to security-critical files. Its list is a sensible default:

- Authentication, authorisation and cryptography code.
- Identity and access policy.
- CI/CD workflow definitions and deployment manifests.
- Sandbox and network policy.
- To which we would add dependency manifests and lockfiles, covered below.

Enforce this with code owners and branch protection, not a sentence in the policy. AISVS is blunt about agents: AC.8.1 says they must not approve, merge, sign or deploy what they generated, enforced by the source control and CI systems, and "policy alone does not satisfy this control."

## Dependencies and the supply chain

Assistants suggest packages. Some are out of date, some carry known vulnerabilities, and some do not exist. The [OWASP cheat sheet on secure coding with AI](https://cheatsheetseries.owasp.org/cheatsheets/Secure_Coding_with_AI_Cheat_Sheet.html) describes attackers registering the package names assistants invent, so that the next developer who installs the suggestion gets their code. [LLM03: Supply Chain](https://genai.owasp.org/llmrisk/llm032025-supply-chain/) covers the wider risk.

The controls are not new, which is the good news. Check that every new package exists, is the one you meant, and is maintained. Run dependency and licence scans on every change. Prefer an internal allowlist or mirror for production code. Treat install scripts as code. Any change to a lockfile should be reviewed as carefully as the code that needed it.

ENISA's draft gives a useful test for evidence here: statements such as "the package is safe" or "all checks passed" "should not be accepted unless they are linked to supporting evidence." An assistant's summary of a scan is not a scan.

## Secrets and data in prompts and output

What goes into a prompt may leave your estate, depending on the tool and its terms. Keep secrets and credentials out of the context the assistant can read, and scan prompts and generated code for them, not only commits. AISVS AC.3.1 and AC.3.2 ask for written rules backed by technical redaction. Where personal data could reach a prompt, UK GDPR applies, and the ICO's [guidance on AI and data protection](https://ico.org.uk/for-organisations/uk-gdpr-guidance-and-resources/artificial-intelligence/guidance-on-ai-and-data-protection/) is the reference.

Watch the output side as well. Generated code sometimes hard-codes a credential from an example, logs more than it should, or turns off a security check to make a test pass. [LLM02: Sensitive Information Disclosure](https://genai.owasp.org/llmrisk/llm022025-sensitive-information-disclosure/) and [LLM05: Improper Output Handling](https://genai.owasp.org/llmrisk/llm052025-improper-output-handling/) describe the related risks.

## Checks that must pass before merge

None of these checks is specific to AI. What changes is that they must be mandatory and blocking, because the volume of change no longer allows judgement calls on each one.

**Checks before merge: where they run and what they block**

| Check | Where it runs | What it blocks |
| --- | --- | --- |
| Unit and integration tests | CI on every pull request | Merge on failure |
| Static analysis | CI on every pull request | Merge on findings above your severity threshold |
| Secret scanning | Pre-commit and CI | Commit or merge when a secret is found |
| Dependency and licence scan | CI when manifests or lockfiles change | Merge on known vulnerable or disallowed packages |
| Infrastructure and pipeline policy checks | CI on infrastructure and workflow changes | Merge on policy violations |
| Required human review | Branch protection and code owners | Merge without an approver other than the requester |

## Provenance: what to record, and what it proves

For each change, record enough to answer later questions: which assistant or agent was involved and in what version, what it was asked to do, which checks ran and with what result, and who approved the merge. ENISA's draft lists what was changed, why, which checks were performed, the results, and who reviewed or approved. AISVS AC.5.1 asks for prompts and responses logged with identifiers that link prompt, response, commit, build and deployment.

The [NIST SSDF](https://csrc.nist.gov/pubs/sp/800/218/final) already asks producers to keep provenance data for the components of each release, and NIST's [SP 800-218A](https://csrc.nist.gov/pubs/sp/800/218/a/final) (July 2024) extends the framework for generative AI. SSDF 1.2 is in draft as SP 800-218 Rev. 1. Signed provenance, of the kind SLSA describes, is the mature form of this record.

Be clear about its limits. Signed provenance shows how a change was produced and that the record has not been altered since. It does not show that the code is correct or secure. That is still the job of review and testing.

## Agents that open pull requests

Once an agent can push branches and open pull requests, treat it as a non-human identity with its own credentials, scoped to the repositories and actions it needs, and short-lived where the platform allows. It should not be able to change branch protection, required checks or its own permissions. AISVS AC.8.2 and AC.8.3 cover both points.

Be careful with automation that runs on untrusted pull request content with access to secrets. A review bot that reads a hostile pull request is exactly the confused deputy the OWASP cheat sheet warns about. Run such jobs without secrets, or only after a person has looked at the change.

## A checklist for the first month

- [ ] Branch protection requires an approver who is not the requester, on every repository where assistants are used.
- [ ] Code owners cover authentication, cryptography, access policy, pipeline files and lockfiles.
- [ ] Agents run under their own identities and cannot approve or merge their own changes.
- [ ] Secret scanning runs before commit and in CI.
- [ ] Dependency and licence scans block merges on findings.
- [ ] Each pull request records which assistant was involved and what it was asked.
- [ ] Workflows that run on outside pull requests have no access to secrets.
- [ ] The rules are written into your [AI coding assistant policy](https://comonad.co.uk/guides/ai-coding-assistant-policy), with a named owner for exceptions.

## How Comonad helps

If you want these rules wired into your repositories and pipelines, with the records an auditor will ask for, that is the work of an AI-enabled SDLC engagement.

## Frequently asked questions

### Is AI-generated code less secure than human-written code?

Treat it as neither better nor worse by default. It can contain the same flaws as human code, sometimes more confidently presented, and arrives in larger volumes. The defence is the same set of requirements, review and tests, applied without exceptions.

### Can an AI tool review AI-generated code?

As an extra check, yes. As the approver, no. OWASP AISVS AC.4.1 says the AI agent does not count as the human reviewer, and that the reviewer must not be the person who asked for the code.

### What should we record about AI-assisted changes?

Which assistant or agent was involved, what it was asked to do, which checks ran and with what result, and who approved the merge. Link the record to the commit, build and deployment so it can be followed later.

### Does signed provenance prove the code is safe?

No. It shows how a change was produced and that the record has not been tampered with. Whether the code is correct and secure is still a question for review and testing.

### Which standards cover this?

NIST SSDF (SP 800-218) and its generative AI profile (SP 800-218A), the SLSA source track, the OWASP AI Security Verification Standard and its appendix on AI-assisted coding, the OWASP Top 10 for LLM Applications, the NCSC and CISA guidelines for secure AI system development, and ENISA's draft advisory on AI-assisted software development.

## Sources

- [ENISA Technical Advisory on AI-assisted software development (draft, version 0.4, September 2026)](https://www.enisa.europa.eu/sites/default/files/2026-09/ENISA%20Technical%20Advisory-AI-assisted-software-development-draft.pdf)
- [OWASP AI Security Verification Standard 1.01, Appendix C: AI-assisted secure coding](https://github.com/OWASP/AISVS/blob/main/1.01/en/0x92-Appendix-C_AI_for_Code_Generation.md)
- [OWASP Cheat Sheet Series: Secure Coding with AI](https://cheatsheetseries.owasp.org/cheatsheets/Secure_Coding_with_AI_Cheat_Sheet.html)
- [OWASP Top 10 for LLM Applications (2025)](https://genai.owasp.org/llm-top-10/)
- [NIST SP 800-218: Secure Software Development Framework 1.1 (February 2022)](https://csrc.nist.gov/pubs/sp/800/218/final)
- [NIST SP 800-218A: SSDF Community Profile for generative AI and dual-use foundation models (July 2024)](https://csrc.nist.gov/pubs/sp/800/218/a/final)
- [NIST SP 800-218 Rev. 1: SSDF 1.2 (initial public draft, December 2025)](https://csrc.nist.gov/pubs/sp/800/218/r1/ipd)
- [SLSA v1.2: source requirements](https://slsa.dev/spec/v1.2/source-requirements)
- [NCSC: Guidelines for secure AI system development (27 November 2023)](https://www.ncsc.gov.uk/collection/guidelines-secure-ai-system-development)
- [CISA: Secure by Design](https://www.cisa.gov/securebydesign)
- [ICO: guidance on AI and data protection](https://ico.org.uk/for-organisations/uk-gdpr-guidance-and-resources/artificial-intelligence/guidance-on-ai-and-data-protection/)

## Related

- [AI-enabled SDLC](https://comonad.co.uk/services/ai-sdlc)
- [AI agent security and red teaming](https://comonad.co.uk/services/ai-agent-security)
- [Legacy modernisation](https://comonad.co.uk/services/legacy-modernisation)
- [AI coding assistant policy](https://comonad.co.uk/guides/ai-coding-assistant-policy)
- [How to set up an AI-enabled SDLC in a large organisation](https://comonad.co.uk/guides/ai-sdlc-enterprise)
- [Verifying AI-written code: independent acceptance](https://comonad.co.uk/guides/verifying-ai-written-code)
- [Swarm-driven development: running software delivery with agent swarms](https://comonad.co.uk/guides/swarm-driven-development)
- [Plan first, then route: orchestrating an AI SDLC across agent harnesses](https://comonad.co.uk/guides/planning-ai-sdlc-orchestration)
- [What an AI agent harness is](https://comonad.co.uk/guides/ai-agent-harness)
