Coding agents propagate vulnerabilities in codebasesCoding Agents Propagate Vulnerabilities in Code Bases
The authors state that frontier coding agents propagate existing vulnerabilities in the codebase into new code: in C/C++ repository tasks, insecure context lowers passsec by an average of 35.4%.
- Coding agents write a large amount of production code, but whether vulnerabilities in existing code are carried by agents into new code and thus accumulate with contributions previously lacked empirical study.
- The authors design two controlled evaluation groups: in 96 backend generation tasks, secure or insecure neighbor applications are placed; in 20 pairs of real C/C++ repository tasks, the security of similar code is changed; only context security is varied while the task is held constant, and passsec of generated code is compared.
- Insecure context reduces the security of generated code across all tested agents: backend generation drops by 3.4% on average, C/C++ repository tasks show a 35.4% average gap; prompts can amplify or mitigate but cannot prevent propagation; in 76.5% of cases agents attribute the vulnerable implementation to following existing code.
- The authors state that the experiments cover only a single implementation step, with long-term codebase evolution left for future work; the C/C++ tasks comprise only 20 pairs from public projects, raising data contamination concerns; the backend tasks are synthetic repositories; the paper does not report statistical significance tests.
- Threat model
- Developers have coding agents implement new features in existing repositories; the repository may unintentionally contain vulnerabilities. The agent has ordinary repository access and is not told to reference relevant code unless the prompt explicitly requires it. The paper explicitly does not study attacks that deliberately plant vulnerabilities to steer the agent (such as poisoned retrieval examples).
- Evaluated models
- GLM 5.3Claude Opus 5GPT-5.6 SolClaude Opus 5.5GPT-6 Astra
- Benchmarks
- AutoBaxBenchCyberGym
- Metrics
- passsec∆passsectrigger rate
Researchers at ETH Zurich used two sets of evaluations to test whether coding agents carry vulnerabilities from existing code into newly written code, and the results show that all the frontier models evaluated propagate vulnerabilities. In 96 backend generation tasks, when an insecure neighboring application was present, the proportion of implementations that were both correct and secure fell by an average of 3.4%, with GLM 5.3 falling 4.5% and Claude Opus 5 falling 2.1%; in 20 pairs of repository-level tasks taken from 5 C/C++ projects, the average gap between insecure and secure contexts reached 35.4%, with GPT-5.6 Sol dropping from 91.0% to 42.0%. Requiring adherence to the existing code style amplifies propagation, while reminders to be careful or generic security hints reduce but cannot eliminate it. When asked to explain implementation choices, the agents attributed them to following another similar piece of code in 76.5% of cases, even though they identified the vulnerabilities they had introduced in 69.9% of their self-reviews.
Why it was selectedThe paper used two sets of evaluations to quantify how existing insecure code lowers the output safety of coding agents, and shows that prompts can only reduce, not prevent, this propagation.
Paper analysis
What problem does this paper attempt to solve?
Whether coding agents propagate existing vulnerabilities in a codebase into newly written code; the authors state this is the first empirical study of this question.
Core question: whether existing vulnerabilities in a codebase cause coding agents to introduce similar vulnerabilities in new code, thereby gradually degrading codebase security with agent contributions.
- Setting and importance: Coding agents (such as Claude Code and Codex) are widely used in production software development; the authors cite a survey stating that 68% of professional developers use such tools daily, and that the proportion of manual review is declining. If agents treat existing vulnerabilities as templates, each contribution may introduce more vulnerabilities.
- Gaps in existing research: Prior work has studied bare LLMs generating vulnerable code and the effect of secure or insecure examples in prompts on non-agent code completion, but the authors note that no one has yet studied how codebase vulnerabilities evolve over time under coding agent contributions.
- Core observation: A key capability of coding agents is to automatically explore the repository and load existing code into context; the authors believe this double-edged sword may lead agents to follow existing vulnerability patterns rather than avoid them.
- Contributions of the paper: The authors propose two complementary evaluations (96 backend generation tasks, 20 pairs of real C/C++ repository tasks) that vary only the security of existing code while holding the task constant, systematically answering 5 research questions (RQ1–RQ5), covering whether propagation exists, whether secure patterns are also adopted, the effect of prompts, applicability across vulnerability categories, and the agents' self-explanations.
- Threat model:
- Victim system: A development workflow in which a coding agent implements new functionality in an existing repository.
- Attacker goal: The paper studies unintentional risk—vulnerabilities that unintentionally exist and persist in the repository.
- Knowledge and capability: The agent has ordinary access to the repository and is not told to reference relevant code unless the prompt explicitly requires it.
- Explicit exclusions: Attacks that deliberately plant vulnerabilities to steer the agent (such as poisoned retrieval examples) are declared out of scope by the authors.
What related research exists?
Related work falls into three groups: coding agents, code security benchmarks, and the effect of context on generated code; this paper moves the context security problem into the agent setting.
Coding agents
- SWE-agent (Yang et al., 2024), AutoCodeRover (Zhang et al., 2024), etc.—equip LLMs with tools to read and write code, execute command lines, etc., and add tool outputs to context, enabling agents to autonomously explore repositories, build, and verify code.
- The paper notes that many studies on the security of generated code target direct LLM inference (e.g., Vero et al. [7], CWEval [22]), whereas in practice developers increasingly use LLMs through agents.
Code security benchmarks
- BaxBench (Vero et al., 2025), AutoBaxBench (von Arx et al., 2026), SecRepoBench (Shen et al., 2026), etc.—have models implement standalone applications or solve real repository issues, measuring correctness with unit tests and detecting vulnerabilities with pre-written end-to-end exploits; the paper notes that such tests are an upper bound on security, and this paper's evaluation is built on AutoBaxBench.
- CyberGym (Wang et al., 2026), CVE-Bench, BountyBench, etc.—evaluate the ability to discover, reproduce, exploit, or fix vulnerabilities; the authors state that these abilities are orthogonal to the security of generated code, and this paper's experiments will demonstrate this.
Effect of context on generated code
- Pearce et al. (2025)—placing secure or insecure example functions in the prompt changes the security of Copilot completions.
- Huang et al. (2026) and Dinh et al. (2023)—defective commented code and buggy prefixes cause models to reproduce defects, and instructions to ignore them only partially mitigate.
- Lyu et al. (2026)—insecure patterns in IDE-collected context (including edit history) propagate into next-edit suggestions.
Baselines and benchmarks: This paper does not compare against other methods, but compares results for the same task under different context variants (secure R+, insecure R−, no neighbor R∅); the benchmarks are AutoBaxBench (backend generation) and CyberGym (C/C++ repository tasks).
The authors position this paper as extending the problem of context affecting code security from single completions/suggestions to autonomous coding agents—agents that explore repositories on their own, choose which implementation patterns to follow, and generate code through multi-step tool calls.
How does the paper address this problem?
The two controlled evaluations vary only the security of existing code: 96 backend tasks with secure/insecure neighbors, 20 pairs of C/C++ tasks with similar code changed, comparing passsec.
Overall approach: construct repository variants that differ only in context security, have the agent complete exactly the same task, and measure generated code with both functionality and security judgments, thereby attributing security differences to existing code. The framework is built around the metric passsec (the proportion of implementations that are both correct and vulnerability-free).
Problem setting and formalization
- Repository R, task t = (d, ℓ) (functionality description d, location ℓ), agent A samples implementations y ∼ A(R, t, p); functionality judgment passt(y) ∈ {0,1}, security judgment sec_v(y) ∈ {0,1} (by CWE class v).
- Core metric passsec(C) = Et Ey ∼ A(C,t,p)[∏v ∈ V(t) passt(y) × secv(y)], i.e., the proportion across tasks and samples of "passing functionality tests and containing no applicable vulnerability".
- Context variants: secure R+, insecure R−, no relevant code R∅; vulnerability propagation is defined as passsec(R−) < passsec(R∅) 或 passsec(R−) < passsec(R+),安全模式采纳定义为 passsec(R+) > passsec(R∅).
Backend application generation (controlled setting)
- Tasks: 24 scenarios × 4 frameworks (Python-Flask, Go-net/http, JavaScript-Express, Rust-Actix) selected from AutoBaxBench, 96 tasks in total, covering seven classes CWE-20/22/78/79/89/522/863.
- Security test modification: Each exploit was split so that it tests only a single CWE class, with unified payloads and the strictest judgment criteria for the same class; implementations generated by Sonnet-5 and GPT-5.6 Luna were used to validate the modified tests.
- Context construction: Neighbor applications are independent of the target functionality; 10 candidates were generated each by Sonnet-5 and GPT-5.6 Luna, and the one with the fewest functionality failures and the most security failures was selected; after fixing functionality issues, secure/insecure variants were constructed with Claude Code (Claude Opus 4.8) following handwritten reference patches, and every change was manually checked.
C/C++ repository-level code generation (real setting)
- Task source: From 1507 CyberGym instances, through four filtering steps (patches limited to a single function leaves 804 → fuzzy matching to similar code leaves 253 → manual review of about 50 → verification that the repository contains the information needed for the fix), 20 instances were finally obtained, from five projects: c-blosc2, FFmpeg, Ghostscript, libxml2, and OpenSC.
- Task construction: The contiguous region involved in the ground-truth patch was replaced with a placeholder, and a functionality description not containing the vulnerability requirement was handwritten; depending on how many secure/insecure similar sites exist in the repository, the original repository was used as one variant and the other variant was manually rewritten.
- Judgment: Functionality passes if the patch applies and the project builds; the ground-truth PoC is run, and a crash means the target vulnerability is present. Each context variant was built once with the pre-patch and post-patch code to verify that the context change does not affect the target vulnerability status.
Prompt interventions and follow-up questions
- Context instructions (Table III): none (no addition), follow_style (require following repository structure and code style), careful (warn against introducing bugs from existing code).
- Security prompt: none or generic (require following security best practices, wording taken from BaxBench).
- RQ5 follow-up questions: For implementations that reproduce vulnerabilities under C/C++ insecure context, ask "does the implementation contain a bug" and "why was it implemented this way", and manually classify by two criteria; additionally, LLM judges (Claude Opus 5.5 and GPT-6.1 Sol) determine whether the final response warns the user; Appendix F gives the full judge prompts.
What experiments did the paper conduct?
All tested agents generate less secure code under insecure context: backend drops by 3.4% on average, C/C++ gap is 35.4% on average; prompts only modulate and do not prevent.
Experimental Setup
- Models tested: GLM 5.3, Claude Opus 5, and GPT-5.6 Sol participated in both evaluation groups; Claude Opus 5.5 and GPT-6 Astra participated only in the C/C++ tasks. Each used its native or recommended harness (Claude Code 2.1.228, Codex 0.147.0), with reasoning levels shown in Table II.
- Benchmarks: the backend generated 96 tasks (24 scenarios × 4 frameworks, adapted from AutoBaxBench); C/C++ repository tasks comprised 20 pairs (adapted from CyberGym, 5 projects).
- Metrics: passsec = the proportion of implementations that pass functional tests and contain no applicable vulnerabilities; ∆passsec is the difference between the two conditions; RQ4 additionally uses trigger rate (the rate at which security tests are triggered).
- Determination method: the backend used functional unit tests + end-to-end exploits; C/C++ used build + PoC crash determination. Warning determination in RQ5 used dual review by Claude Opus 5.5 and GPT-6.1 Sol, and the authors state that the two had highly consistent labels.
- Sampling: backend 3 runs per model × task × condition, C/C++ 5 runs; RQ5 analyzed the first 3 generations per task. The paper does not report statistical significance tests.
Main Results
RQ1/RQ2 main results (Figure 4, none instruction + none safety hint, ∆passsec in percentage points):
Swipe horizontally to read the table
Model Backend: insecure neighbor vs. independent Backend: secure neighbor vs. independent C/C++: insecure vs. secure context GLM 5.3 −4.5 +1.4 −35.0 Claude Opus 5 −2.1 +2.8 −37.0 GPT-5.6 Sol −3.5 +9.0 −49.0 Claude Opus 5.5 not reported not reported −25.0 GPT-6 Astra not reported not reported −31.0 - In backend generation, insecure neighbors reduced passsec by an average of 3.4%, secure neighbors increased it by an average of 4.4%, and the average gap between secure and insecure neighbors was 7.8%; GPT-5.6 Sol had the largest gap (12.5%).
- In C/C++ tasks, the secure/insecure context gap for the five models was 25.0%–49.0%, averaging 35.4%; GPT-5.6 Sol dropped from 91.0% in the secure context to 42.0% in the insecure context.
- The authors state: the agent introduces vulnerabilities similar to existing bugs into new code, even when the existing code is unrelated to the task's functionality; the effect is stronger when surrounding code needs to be examined.
RQ3: Prompt Interventions
- follow_style amplifies bidirectional effects: under insecure neighbors in the backend, GLM 5.3's decrease expanded from 4.5% to 9.0% (Figure 6); in C/C++, follow_style widened the context gap for all models, with GPT-5.6 Sol reaching 55.0% (Figure 8).
- careful weakens both directions: it narrowed the context gap for all models, but the secure context was still better in all cases; the authors believe the careful instruction overall reduces reliance on existing code rather than selectively filtering insecure patterns.
- generic safety hint: independent backend generation passsec rose from 41.7%/69.8%/47.2% (GLM 5.3/Opus 5/Sol) to the corresponding values among 75.0%/74.7%/44.8% (Figure 5, Sol is 44.8%); under follow_style it reduced but did not eliminate the harm from insecure neighbors (Figure 7); in C/C++, GPT-5.6 Sol reached 100% passsec in the secure context, while the insecure context still dropped to 68.0%.
RQ4 and RQ5
- RQ4 non-applicable vulnerability categories: when the neighbor's CWE class does not overlap with the target, the effect on generated code security is small and inconsistent (Figure 9); same-class insecure neighbors increased the trigger rate for CWE-522, CWE-22, and CWE-79 the most (Figure 11), while cross-class effects were small and inconsistent (Figure 12). The authors state that the agent mainly propagates vulnerabilities of the same applicable category as the target.
- RQ5 identification and attribution: for implementations that introduced vulnerabilities in the insecure context, the proportion of target vulnerabilities identified during review by the three models ranged from 64.2% (Opus 5.5) to 75.8% (GPT-6 Astra), averaging 69.9%; in explanations, 75.0%–78.8% attributed it to following another code location containing a similar vulnerability, averaging 76.5% (Table IV).
- Missing warnings: the proportion of final responses that proactively warned about the target vulnerability was only 11.8% (Opus 5.5) and 5.9% (Opus 5), with GLM 5.3, GPT-5.6 Sol, and GPT-6 Astra at 0% (Table VII).
Other Ablations and Analyses
- Number of neighbors (Figure 10, follow_style): increasing from 1 to 5 neighbors amplified both the secure and insecure bidirectional effects (e.g., GLM 5.3 insecure neighbor −5.2%→−9.0%, secure neighbor +4.2%→+7.6%).
- Source retrieval (Table VIII): GPT-5.6 Sol attempted to retrieve the project's original source code in 50.0% of generations, while the other models did so at most 3.5%; all attempts failed due to the container being offline.
- Memory statements (Table IX): 64.0% of GLM 5.3's reasoning traces contained statements recalling the original code, while other models' messages contained at most 1.0%; the authors state this does not prevent propagation.
- Exceptions: the benefit of careful relative to none varied by model—Opus 5 recovered to the independent level, GLM 5.3 improved partially, and GPT-5.6 Sol showed no change; under the generic hint, secure neighbors provided almost no additional benefit.
What are some points that can be further explored?
The authors state that the experiments cover only a single implementation step, with long-term evolution left for future work; the evaluation scale is 96 backend tasks and 20 pairs of C/C++ tasks.
Limitations and future directions noted by the authors
- Single-step implementation: Discussion §VII-C notes that the experiments study only one implementation step, and only raise concerns about long-term security evolution of codebases; the Conclusion states that studying how the security of real codebases evolves with agent contributions is an important future direction.
- Data contamination concerns: §VI-G and Appendix C-C note that the C/C++ tasks come from public open-source projects, and agents may have seen the original code during training; recall accuracy is hard to assess because it is impossible to determine which version the agent recalls.
- Lower-bound nature of security judgment: §III notes that the security oracle can only provide a lower bound—it cannot rule out the existence of vulnerabilities that were not detected, nor the existence of other categories of vulnerabilities.
- Laxness of functionality judgment: §V-A notes that C/C++ tasks use build success as the functionality check, because the handwritten descriptions do not fully specify all details.
- Dataset size and expansion: §V-A notes that the heavy workload of manual review makes the C/C++ evaluation set 20 instances, and states that the construction pipeline can be used to expand this dataset in the future.
- Mitigation directions: §VII-D proposes mitigation directions at three levels: model training alignment, harness default settings, and developer workflows; these are author suggestions rather than validated solutions.
Scope of experimental coverage
- 5 models were tested: GLM 5.3, Claude Opus 5, GPT-5.6 Sol (two evaluation groups), Claude Opus 5.5, GPT-6 Astra (C/C++ only).
- Backend tasks are synthetic service repositories (adapted from AutoBaxBench, 96 tasks, 7 CWE classes, 4 frameworks); C/C++ tasks are 20 pairs from 5 real open-source projects, covering only memory-safety vulnerabilities.
- Number of samples: 3 per condition for backend, 5 for C/C++; the paper does not report statistical significance tests or confidence intervals.
- Prompt interventions cover only the three context instructions and one generic security prompt in Table III; the paper does not test other defenses or adaptive attacks (the threat model itself contains no attacker).
- The follow-up analysis for RQ5 covers only the first 3 generations of three models—GLM 5.3, Claude Opus 5.5, and GPT-6 Astra—under C/C++ insecure context.
Summarize the main content of the paper
The authors state that frontier coding agents propagate existing vulnerabilities into new code as templates, that prompts can only modulate but not prevent this, and that agents' knowledge and actions are inconsistent.
An empirical study on the security risks of coding agents: whether vulnerabilities in existing code are carried by agents into new code.
- Problem: Coding agents write a large amount of production code and manual review is decreasing, but how codebase vulnerabilities evolve under their contributions had not been studied before.
- Method: Two controlled evaluations vary only context security—in 96 backend generation tasks, secure/insecure/no neighbor applications are placed; in 20 pairs of real C/C++ repository tasks (adapted from CyberGym), the security of similar code is rewritten; results are measured with passsec (functionality passes and no vulnerability).
- Propagation exists: Insecure neighbors reduce backend generation passsec by 3.4% on average; in C/C++, the average gap between secure and insecure context reaches 35.4% (25.0%–49.0%, all five models are worse under insecure context).
- Prompts do not solve the problem: follow_style amplifies propagation (largest C/C++ gap 55.0%), while careful and generic security prompts shrink but do not eliminate the gap; when GPT-5.6 Sol has 100% passsec under secure context, it still drops to 68.0% under insecure context.
- Knowing–doing gap: During review, agents can identify their own introduced vulnerabilities 69.9% of the time on average, and 76.5% attribute the implementation to following existing code, but the highest proportion that proactively warn the user in the final response is only 11.8%.
- Authors' conclusion: Vulnerability propagation is a risk across frontier agents, exposing a misalignment between security knowledge and implementation behavior; as the proportion of code written by agents rises, vulnerabilities may accumulate with contributions, requiring coordinated mitigation in three areas: training, harness default settings, and proactive vulnerability fixing.