system: OPERATIONAL
← back to all hacks
AGENTS MEDIUM NEW

Coding agents copy the vulnerabilities already in your codebase

ETH Zurich researchers show that coding agents reuse insecure patterns from nearby code as templates. In C/C++ repositories, insecure context cut secure output by 35.4 points on average.

2026-11-18 // 6 min affects: claude-code, codex, claude-opus-5, claude-opus-5.5, gpt-5.6-sol, gpt-6-astra, glm-5.3

What is this?

On November 8, 2026, researchers from ETH Zurich’s SRI Lab (Chenhao Sun, Niels Mündler-Sasahara, Mark Vero and Martin Vechev) published Coding Agents Propagate Vulnerabilities in Code Bases on arXiv. The question is simple: when a coding agent writes new code inside an existing repository, does it pick up the security flaws of the code around it?

The answer is yes. The authors find that agents treat existing code as a template, including its bugs. Insecure neighboring code made agents write vulnerable code more often in both settings they tested. The evaluation code is public on GitHub under an MIT license.

This is not an attack. Nobody plants anything. It is a quality and security risk that grows quietly as agents write more production code with less human review.

How it works

The team ran the same task twice for each agent, in two versions of a repository that differ only in whether nearby, independent code is secure or insecure. The main metric, sec_pass, is the share of outputs that are both functionally correct and free of the targeted vulnerability.

Two settings were used:

  • Backend generation (96 tasks). 24 AutoBaxBench scenarios across Flask, Go net/http, Express and Actix. The agent builds a new web service next to existing ones. The neighbors cover seven weakness classes: input validation, path traversal, OS command injection, XSS, SQL injection, insecure credential storage and broken authorization.
  • C/C++ repository-level coding (20 task pairs). Drawn from CyberGym and five real projects: libxml2, FFmpeg, Ghostscript, OpenSC and c-blosc2. The agent fills a masked function at the site of a known memory-safety bug. A proof-of-concept input checks whether the bug comes back.

The agents tested, as named in the paper, include Claude Code with Claude Opus 5 and GLM 5.3, Codex with GPT-5.6 Sol, plus Claude Opus 5.5 and GPT-6 Astra on the C/C++ tasks.

Schematically, the failure looks like this:

repo/
  service_a/   handler builds file path from user input, no normalization   <- old flaw
  service_b/   (new) agent asked to "add a download endpoint"
     -> agent reads service_a for conventions
     -> reproduces the same unchecked path join

Why it matters

The key numbers:

SettingEffect of insecure context
Backend, vs. standalone generation-3.4 points of secure-and-correct output on average (GLM 5.3: -4.5, Opus 5: -2.1)
C/C++, secure vs. insecure context35.4-point gap on average, up to 49.0

The C/C++ result is the striking one. When the surrounding code handled memory safely, agents mostly did too. When it did not, they often copied the unsafe pattern.

Two other findings matter for teams:

  • Agents know what they did. Asked to explain their choices, agents said they followed another code site in 76.5% of cases. Asked to review their own vulnerable code, they spotted the flaw in 69.9% of cases. The problem is not missing knowledge. It is that “match the codebase” wins over “write safe code” during generation.
  • Prompts help, but not enough. Telling the agent to follow the existing code style increased propagation. A generic security hint, or an explicit warning to be careful with existing code, reduced it but did not stop it. Secure neighbors, on the other hand, improved security compared with no context at all.

The long-term effect is what the authors stress: codebases can slowly get worse if known flaws are not fixed, because each agent-written feature can copy them. Legacy code becomes training material for every new change.

Defenses

  1. Fix the baseline first. The authors’ main message is to fix existing vulnerabilities thoroughly and continuously. Before rolling coding agents onto a legacy repo, run SAST and dependency scans and clear the known findings, starting with the patterns agents are most likely to copy (path handling, query building, auth checks, buffer handling).
  2. Do not ask for blind style matching. Avoid instructions such as “follow the existing code exactly” in agent prompts and repo rules. The paper shows this increases propagation.
  3. Add a standing security instruction. A generic security hint in the agent’s system or project instructions measurably reduced vulnerable output. It is cheap, so use it, but do not rely on it alone.
  4. Run a self-review pass. Agents recognized their own flaws in about 70% of cases. A second, review-only step (“check this diff for the weakness classes above”) catches part of what generation misses.
  5. Scan agent diffs in CI. Treat agent-written code like any untrusted contribution: SAST, fuzzing for C/C++ changes, and required human review on security-sensitive paths.
  6. Mark known-bad code. Where a flawed pattern cannot be fixed yet, isolate it, document it as deprecated, or keep it out of the context the agent reads.
  7. Provide secure reference code. Since secure neighbors improved results, keep clean, reviewed examples of common patterns in the repo for agents to imitate.

Status

ItemDetail
PaperCoding Agents Propagate Vulnerabilities in Code Bases (arXiv 2611.11455)
Published2026-11-08
AuthorsSun, Mündler-Sasahara, Vero, Vechev (ETH Zurich)
Agents testedClaude Code (Opus 5, GLM 5.3), Codex (GPT-5.6 Sol), Opus 5.5 and GPT-6 Astra on C/C++
BenchmarksAutoBaxBench (96 backend tasks), CyberGym (20 C/C++ task pairs)
TypeSystemic behavior, no vendor patch applicable
Codeeth-sri/vulnerability-propagation (MIT)

Sources