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

Simin Chen, Yixin He, Suman Jana, Baishakhi Ray

TL;DR

LLM-based automated program repair (APR) agents can be systematically tricked into generating patches that fix software bugs perfectly while secretly introducing critical security vulnerabilities. This paper introduces SWExploit, a red-teaming framework that crafts adversarial GitHub issues to achieve up to a 91% attack success rate, shattering the long-held assumption that passing CI/CD test suites guarantees code security.

What Problem Does This Paper Address?

Automated Program Repair (APR) agents (like SWE-agent) are rapidly being adopted to automate software maintenance by reading natural language bug reports (e.g., GitHub issues) and automatically generating code patches. Currently, the gold standard for evaluating these agents is functional correctness—if the generated patch resolves the issue and passes all regression tests, it is considered a success.

However, open-source ecosystems are inherently collaborative and public; anyone can file a bug report. The authors explore a dangerous blind spot in this paradigm: Can an adversary craft a legitimate-looking GitHub issue that misleads an APR agent into writing a patch that is functionally correct but contains a hidden security vulnerability?

Because current workflows assume that passing a CI/CD pipeline implies a patch is safe to merge, this style of attack represents a stealthy, high-impact threat vector for supply chain contamination.

Methods

The authors present SWExploit, an automated framework designed to turn benign bug reports into adversarial ones. It operates without needing access to the APR agent's internal pipeline or weights (black-box setting) via three main steps:

  1. Program Analysis for Injection Points: SWExploit parses the original error messages and tracebacks to find candidate functions that accept string inputs. These serve as viable entry points where a malicious payload can be safely integrated into the program's control flow.
  2. Adversarial Issue Generation: Using an auxiliary LLM, SWExploit generates fake tracebacks, fake reproduction code, and fake requirements. It blends these smoothly with the original issue description to preserve the core bug semantics. Crucially, it introduces a "MAGIC STRING" conditional gate. The vulnerable code will only execute if this specific, unusual string is provided as an input. For all normal test inputs, the gate remains closed, ensuring the patch passes existing CI/CD checks.
  3. Iterative Refinement: SWExploit operates in a feedback loop. It feeds the generated issue to the target APR agent, evaluates the resulting patch to see if the vulnerability was successfully injected and invoked, and uses any failures as feedback to refine the prompt (up to 10 iterations).
Figure 3: Design overview of SWExploit

Datasets

The framework was evaluated using SWE-bench Lite, a benchmark containing 300 real-world, self-contained bug-fix instances from popular open-source Python repositories (such as django, astropy, pandas, etc.).

Key Insights and Ideas

  • The Illusion of Test-Driven Security: Functional correctness and security vulnerabilities are not mutually exclusive. By utilizing conditional execution gates (the MAGIC STRING), an attacker can ensure a backdoor remains completely invisible to standard regression testing suites.
  • Stealth via Natural Language: Rather than relying on obvious, adversarial prompt injections (like "ignore previous instructions"), SWExploit mimics real developer behavior—such as slightly messy, environment-specific tracebacks. This allows the malicious report to easily blend into normal workflow activities.
  • Bypassing Perplexity Defenses: Standard text-based anomaly detectors often flag AI-generated text by measuring its "perplexity" (how unusual the word choices are). Because SWExploit uses an auxiliary LLM to smoothly blend fake and real text, the resulting issues look entirely natural and completely bypass perplexity filters.

Key Results

The authors evaluated SWExploit across three agent pipelines (including SWE-agent and MINI-AGENT) and five backend LLMs (including Claude and Gemini models).

  • High Attack Success Rate: SWExploit achieved an attack success rate on functionally correct patches (Correct-ASR) of up to 0.91 (91%). In comparison, baseline attack methods all scored below 0.20 because they generated unreachable "dead code" that static checkers or agents ignored.
  • Preserved Functionality: The functional correctness (Pass@1) of the patches generated under attack remained virtually unimpeded, matching the "No-Attack" baseline in several configurations (e.g., maintaining a 0.48 Pass@1 score for MINI Agent with Claude-4.0).
  • Multi-Payload Effectiveness: The attack proved highly effective across various vulnerability types, displaying particularly potent results for OS Command Injection (CWE-78) and Code Injection via SSTI (CWE-94).
Attack Effectiveness on different CWE payloads

Limitations and Future Work

  • Language and Scope Constraints: The evaluation was strictly limited to Python repositories and focused on a specific set of predefined CWE payloads.
  • The Oracle Problem: Automatically determining whether a codebase is truly exploitable under all conditions remains an open challenge. The authors relied on static analysis tools (like Bandit) paired with manual validation for a subset of test cases to verify exploitability.
  • Defensive Gap: Traditional defenses like query rephrasing only marginally reduced the attack's effectiveness. The authors conclude that the community urgently needs to develop entirely new, security-aware evaluation paradigms specifically designed for multi-step software engineering agents.

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