AutoPatch: Multi-Agent Framework for Patching Real-World CVE Vulnerabilities

Minjae Seo, Wonwoo Choi, Myoungsung You, Seungwon ShinarXiv 2025 · DOI

Abstract

Large Language Models (LLMs) have revolutionized software development but are constrained by a "knowledge cutoff," often generating code that contains recently discovered security vulnerabilities. We present AutoPatch, a multi-agent framework that utilizes Retrieval-Augmented Generation (RAG) to detect and remediate vulnerabilities in LLM-generated code. By aligning generated code patterns with a database of Common Vulnerabilities and Exposures (CVEs), AutoPatch achieves high patching accuracy (94.1%) at a fraction of the cost of model retraining.

Introduction

The rapid disclosure of thousands of new CVEs annually poses a significant challenge for LLMs. Models trained on data preceding these disclosures may inadvertently suggest "best practices" that have since been identified as high-severity vulnerabilities. Traditional mitigation strategies, such as frequent fine-tuning, are economically and computationally expensive. AutoPatch addresses this by acting as an automated security layer that matches generated code against the latest security intelligence.

Methodology: The AutoPatch Architecture

AutoPatch operates as a multi-agent system integrated into the developer workflow. It consists of three primary agents:

  1. Similarity Analyzer: Employs a dual-pronged approach using Semantic Analysis (keyword/description comparison) and Data Flow Analysis (symbolic representation via CodeQL). This allows the system to identify vulnerabilities even when variable names or surface-level structures differ from the original CVE source.
  2. Vulnerability Verifier: Confirms potential vulnerabilities using one-shot prompting. It analyzes the root cause by comparing the generated code against specific CVE examples retrieved from the RAG database.
  3. Code Patcher: Generates secure code revisions and operates within a Patch-Verification Feedback Loop. The Verifier iteratively checks the Patcher’s output until the code is confirmed secure.
Detailed architecture of the AutoPatch multi-agent framework including RAG integration and the three-agent pipeline.

Experimental Evaluation

To evaluate AutoPatch, a benchmark dataset was constructed comprising 75 high-severity CVEs from late 2024 and early 2025, targeting critical systems like the Linux kernel and Chrome. The dataset included 525 code snippets generated by state-of-the-art models (e.g., GPT-4o, o3-mini) and various obfuscated versions to test robustness.

Key Results

  • Matching Precision: The system achieved 91.8% accuracy in identifying the correct CVE associated with a code snippet.
  • Detection and Remediation: Paired with GPT-4o, AutoPatch reached an F1-score of 90.3% for detection and a 94.1% accuracy for successful patching.
  • Economic Efficiency: AutoPatch is over 50 times (5,230%) more cost-efficient than non-incremental fine-tuning, processing the entire benchmark for approximately $5.70.
Comparison of LLM-generated code containing vulnerabilities (e.g., dangling pointers) versus the secure, patched versions produced by AutoPatch.

Discussion and Insights

A key finding is that LLMs act as "vulnerability repeaters," consistently reproducing patterns for CVEs released after their training cutoff. AutoPatch demonstrates that abstraction—focusing on symbolic data flow rather than surface-level text—is critical for robust vulnerability detection. Furthermore, the success of the RAG-based approach suggests that providing models with external context is a more scalable solution for fast-moving security domains than weight-based training.

Conclusion and Future Work

AutoPatch provides a reactive but highly effective mechanism for securing LLM-generated code against known CVEs. While currently limited to known vulnerabilities, future iterations aim to expand coverage to more diverse platforms and reduce the latency between vulnerability disclosure and system update.

Summary updated

BibTeX
@misc{seo2025autopatch,
  author = {Minjae Seo and Wonwoo Choi and Myoungsung You and Seungwon Shin},
  title = {{AutoPatch: Multi-Agent Framework for Patching Real-World CVE Vulnerabilities}},
  year = {2025},
  eprint = {2505.04195},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.04195},
}
Figure