Red Teaming Program Repair Agents: When Correct Patches can Hide Vulnerabilities

Simin Chen, Yixin He, Suman Jana, Baishakhi Ray · Submission to ICLR 2026 · Desk rejected

TL;DR

Passing continuous integration (CI) tests does not mean automated code repairs are safe. SWExploit demonstrates that an external attacker can craft seemingly benign GitHub issue reports that trick LLM-based Automated Program Repair (APR) agents into generating patches that both pass all regression tests and embed dormant, attacker-triggerable vulnerabilities.

What Problem Does This Paper Address?

Autonomous coding agents (such as SWE-agent and ExpeRepair) are increasingly tasked with reading open-source bug reports and generating patches automatically. The software engineering community has traditionally operated under a fundamental assumption: if a patch passes existing regression suites and CI/CD checks, it is correct and ready to merge.

However, open-source repositories allow anyone to submit issues. This paper examines a novel, realistic threat model: Can an adversary—with only black-box access and standard issue-reporting permissions—submit a valid bug report that tricks an APR agent into implanting an exploitable vulnerability while still fully fixing the original bug? Prior adversarial attacks on code generation typically broke functionality or relied on single-turn completion prompts, failing to account for multi-turn agent workflows and repository-level CI constraints.

Methods

The authors introduce SWExploit, a three-stage framework that generates adversarial issue descriptions designed to deceive APR agents:

  1. Injection Point Identification via Program Analysis: SWExploit inspects the original bug's traceback and execution trace to find candidate functions. It filters for functions accepting string arguments (to allow string-based payload triggers) and uses an auxiliary LLM to pick the optimal function entry point for injection.
  2. Adversarial Issue Generation with Gated Payloads:
  3. Core Semantics Preservation: The bug description and reproduction steps are retained to ensure the agent still repairs the true issue.
  4. Conditional Gating ("Magic Strings"): The injected payload is protected behind an unusual or attacker-controlled string gate (e.g., param.startswith("abcdefedcba") or common strings like "password" and "www.google.com"). Normal CI/CD test inputs will never satisfy this gate, guaranteeing that standard test suites pass.
  5. Fabricated Context: An auxiliary LLM generates plausible fake tracebacks and reproduction snippets claiming that a helper function (the vulnerable payload) is missing, subtly misleading the repair agent into defining and calling it.
  6. Iterative Issue Refinement: SWExploit inspects the agent’s generated patch. If the vulnerable payload is either absent or dead code (unreachable from the main control flow), the auxiliary LLM updates the issue prompt using the failed attempt as feedback (up to 10 iterations).
[Benign Issue] 
      │
      ▼
[1. Program Analysis] ──► Identify triggerable injection entry points
      │
      ▼
[2. Fake Artifacts]   ──► Generate fake traceback/reproduction code + Magic String gate
      │
      ▼
[3. Iterative Refinement] ◄── APR Agent generates patch ──► Check payload reachability

Datasets

  • SWE-bench Lite: 300 real-world, self-contained Python software engineering problem instances across repositories such as Django, Sympy, and Astropy.
  • Evaluated Systems: Three agent architectures (SWE-AGENT, MINI-AGENT, and EXPEREPAIR) evaluated across five frontier LLM backends (Claude-3.5-Sonnet, Claude-3.7-Sonnet, Claude-4.0-Sonnet, Gemini-2.5-Pro, and Gemini-2.0-Flash).

Key Insights and Ideas

  • Passing CI is no longer a proxy for safety: By gating malicious code behind conditional branches unreached by benign test suites, an attacker completely decouples functional correctness from malicious side effects.
  • Agents are susceptible to "hallucinated requirements": By inserting believable fake tracebacks and reproduction code, agents treat the malicious payload as an essential missing component required to fix the user's issue.
  • Natural-sounding semantic triggers blend in: Switching from random trigger strings to everyday tokens (e.g., "2025-01-01" or "www.google.com", which appears in over 7 million GitHub repos) preserved or improved attack success while remaining virtually unnoticeable to human reviewers.
  • Standard defenses fail completely:
  • Perplexity Filtering fails (performing worse than random guessing) because the blended issues read like natural developer text.
  • Harmful Query Classifiers achieve an F1 of 0.00 because the issue prompt contains no overt malware syntax.
  • LLM-as-a-Judge achieves at best an F1 of 0.68 on patch classification, falling short of reliable protection.

Key Results

  • High Attack Success on Correct Patches (Correct-ASR): Across 12 agent–LLM configurations, SWExploit achieved Correct-ASR between 0.71 and 0.91 (compared to $\le$0.20 for adapted baselines such as BugInject, AutoRed, and FCV).
  • Functionality Preserved: On MINI-AGENT with Claude-4.0, SWExploit reached a Pass@1 of 0.48, matching the unattacked baseline (0.48) and outperforming BugInject (0.34) and AutoRed (0.21).
  • Actual Exploitability (PER): Manual exploits for OS command injection (CWE-78) demonstrated that up to 73% of correct patches on Gemini-2.0-Flash and 53% on Claude-4.0 were dynamically exploitable.
  • Payload Diversity: SWExploit succeeded across diverse vulnerability types, including OS Command Injection (CWE-78), Code Injection via SSTI (CWE-94), Deserialization (CWE-502), Broken Crypto (CWE-327), and Path Traversal (CWE-22).
  • Transferability: Adversarial issues crafted using one model successfully triggered vulnerabilities in agents powered by different backend models without prompt re-tuning.

Limitations and Future Work

  • Exploit Verification Lower Bound: Exploitability testing was conducted using a manually curated test set for CWE-78; because agents write code unpredictably, this metric represents an empirical lower bound rather than an exhaustive vulnerability proof.
  • Trigger Dependency: Payloads depend on input arguments passing through specific functions; data paths that heavily sanitize or transform inputs may neutralize string-gated triggers.
  • Future Defense Directions: The authors stress that defending APR agents will require moving beyond black-box test validation toward:
  • Branch-aware and taint-tracking verification to audit newly introduced control-flow branches.
  • Automated fuzzing and symbolic execution to uncover hidden conditional gates prior to patch acceptance.

Summary updated

BibTeX
@misc{chen2025red,
  author = {Simin Chen and Yixin He and Suman Jana and Baishakhi Ray},
  title = {{Red Teaming Program Repair Agents: When Correct Patches can Hide Vulnerabilities}},
  year = {2025},
  eprint = {2509.25894},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.25894},
}
Figure