Abstract
This paper investigates whether "off-the-shelf" Large Language Models (LLMs) like OpenAI’s Codex can automatically repair security vulnerabilities without any specialized training. While the models successfully repaired 100% of the authors' hand-crafted and synthetic bug scenarios, they struggled with the complexity of real-world historical vulnerabilities, highlighting a significant gap between "passing a test" and providing a truly robust security patch. This resource includes the code framework, prompt templates, and datasets used to evaluate zero-shot repair capabilities across various domains.
Introduction
Software security vulnerabilities (Common Weakness Enumerations, or CWEs) are a persistent threat, and manually writing patches is a slow, expert-intensive process. While previous research focused on training specialized "Neural Machine Translation" models to fix bugs, this paper asks a more provocative question: Can general-purpose LLMs—trained on vast amounts of both buggy and clean open-source code—be "coaxed" into fixing vulnerabilities in a zero-shot setting?
The challenge lies in "prompt engineering." Since these models are essentially high-powered autocompletes, how you phrase the request (the prompt) determines whether the model produces a secure fix, more buggy code, or something else entirely.
Methodology
The researchers evaluated several "black-box" commercial models (OpenAI’s Codex family and AI21’s Jurassic-1) alongside "local" open-source models (Polycoder and their own custom-trained gpt2-csrc).
Their approach involved a multi-tiered evaluation across four domains: synthetic bugs, hand-crafted programs covering the MITRE "Top 25" vulnerabilities, Verilog code for hardware security, and historical real-world CVEs from the ExtractFix dataset. Every suggested fix was run through a pipeline of compilers, functional unit tests, and security "oracles" (like CodeQL or AddressSanitizer) to verify if the bug was actually resolved.
Key Insights and Results
The "Coaxing" Factor and Hyperparameters
The most effective prompt style was often the most verbose one, providing the buggy code as a "commented-out" reference to give the model context. Furthermore, the study found that model hyperparameters significantly impacted success rates. Higher "temperatures" (which increase creativity/randomness) were better for fixing complex memory bugs, while lower temperatures were better for straightforward SQL injections.
Performance Summary
- Hand-crafted Success: Collectively, the LLMs repaired 100% of the 117 hand-crafted and synthetic scenarios when given the right prompt and enough attempts.
- Real-world Reality Check: On 12 real-world CVEs, the models repaired 8 out of 12. While impressive for a zero-shot approach, the fixes were often "brittle" or required manual selection from many candidates.
- Model Rankings: OpenAI’s
code-davinci-002was the clear winner, consistently outperforming smaller or older models.
Discussion and Future Work
A major finding was the discovery of implausible patches. Some LLM-generated fixes passed all functional and security tests but were logically nonsensical (e.g., fixing a buffer overflow by simply deleting the code that processed the data). This warns that automated repair tools need much stronger "oracles" than just basic test suites.
Future hurdles for production include token limits for large source files and the need for automated bug localization. The authors suggest moving toward an "ensemble" approach, where multiple models and prompt styles are used in parallel to find the best possible repair.
Summary updated