← Blog

Secure Code Review When the Author Is an Agent

Marco Masut

Secure code review is the examination of a code change, by a person, a tool or both, to find security flaws before the change reaches production. It looks for things a test suite rarely covers: missing authorisation checks, unsafe handling of input, secrets in the diff, risky dependencies. When an agent wrote the change, the reviewer faces a diff with no intent behind it: nobody can be asked why a line is there, and the volume is higher than a person would produce. Three adjustments keep the review meaningful. Read the change against the request that produced it, not only against itself. Run the mechanical checks as separate, repeatable steps, so that opinion is left for what only a person can judge. Record who reviewed and what they saw, so that the approval can be shown later to a client or an auditor. The sections below show what changes and what must become evidence.

What is a secure code review meant to catch?

It is meant to catch flaws that pass functional tests because the code does what it was asked, and also something it should not. NIST's Secure Software Development Framework, SP 800-218 lists reviewing or analysing human-readable code to find vulnerabilities among its recommended practices, and the OWASP Code Review Guide gives the working method. In practice the review targets a short list:

  • authentication and authorisation: who can call this, and is the check on the server side;
  • input handling: injection, unsafe deserialisation, path traversal;
  • secrets and configuration: keys committed, debug modes left on;
  • dependencies: new packages and what they pull in;
  • error handling and logging: what leaks to the user and what is missing for an investigation.

A review that only checks style and logic is a quality review. It becomes a security review when the reviewer goes through this list on purpose.

What changes when the author is an agent?

Three things change, and none of them is that the code is worse by default.

First, intent disappears. A colleague can explain a choice. An agent's session has closed, and the reasoning, if recorded at all, sits in a log nobody reads. The reviewer has to reconstruct intent from the request and the diff.

Second, volume. An agent can produce a large change in minutes, and review attention does not scale at the same speed. The risk is a quick approval of a diff nobody read in full.

Third, the quality of the choices, dependencies above all. A study presented at USENIX Security 2025 (Spracklen et al., "We Have a Package for You!") generated 576,000 code samples in Python and JavaScript with 16 models and found that the average share of hallucinated packages was at least 5.2% for commercial models and 21.7% for open-source models. A name that does not exist can be registered by an attacker.

| Question | Human author | Agent author | | --- | --- | --- | | Can the reviewer ask why? | Yes, in minutes | No, the session is closed | | Size of the change | Limited by typing speed | Large, produced fast | | New dependencies | Chosen with some context | Possibly invented or unvetted | | Who else read it | Often the author first | Nobody before the reviewer |

What review checklist survives volume?

One that is short, ordered by risk and mostly mechanical. Here is a version that fits most teams:

  1. Read the request first, then the diff. Does the change do what was asked and nothing else? Files touched outside the stated scope are a signal.
  2. Look at the manifest and lockfile before the code. Every new dependency needs a name, a maintainer and a reason.
  3. Search the diff for trust boundaries: new endpoints, new inputs, new queries, new file access. Review those lines slowly.
  4. Check authorisation on every new path, on the server side.
  5. Check secrets and configuration: no keys, no debug flags, no wider permissions than needed.
  6. Confirm the tests exist for the security-relevant behaviour, not only for the happy path.
  7. Write down what you reviewed and what you did not.

The last step matters most. A review that does not say what it left out claims more than it covered.

What must be evidence, not opinion?

Opinion is the right tool for design judgement. It is the wrong tool for anything that can be checked by a program. Move these out of the reviewer's head and into repeatable steps:

  • static analysis and secret scanning, run in a separate step from the one that wrote the code;
  • dependency checks at the moment a package is added, covered in software supply chain security when an agent picks the dependency;
  • tests that can be run again by someone else, with the command and the result kept;
  • the list of files changed compared with the scope that was approved.

The reason is separation of duties: the check that passes should not be run only by the process that wrote the change, as discussed in separation of duties when an agent writes and tests. A model grading its own output is a weak control. A re-runnable check, whose result is stored with the change, is a strong one. For the review tools themselves, see AI code review tools: they help the reviewer, they do not replace the signature.

Who signs the review?

A named person, and the signature must say what it covers. "Approved" with no scope is an opinion. A useful record has four parts: who reviewed, which change and which version of it, which checks ran and their result, and which parts were not reviewed. If the signer cannot be named, the review did not happen in any sense a client, an insurer or an auditor can use.

This is where the process view matters: a review is one station on the line from request to production, not the whole line. The wider picture is in secure SDLC with agents in the loop. Detent, the end-to-end delivery system (detent-ai.com), is built around this point: the system prepares the evidence, a named person signs the plan before work starts and the delivery at the end, and the signature is tied to what was actually checked. For the wider context see AI software development, and for how tools compare on what they leave behind, the benchmark.