How Safe Are AI-Generated Patches? A Large-scale Study on Security Risks in LLM and Agentic Automated Program Repair on SWE-bench
Amirali Sajadi, Kostadin Damevski, Preetha Chatterjee
TL;DR
This work delivers the first large-scale security analysis of patches produced by LLMs and agentic APR systems on real-world SWE-bench issues, comparing them to developer-written fixes. Using SWE-bench, it shows that standalone Llama 3.3 patches introduce markedly more vulnerabilities than developers, with distinct CWE patterns such as eval injection and insecure deserialization. Agentic APR frameworks also generate vulnerabilities, especially when given broad autonomy that leads to extensive cross-file edits. The study further links vulnerability likelihood to code- and issue-level factors (e.g., number of files touched, information completeness in issues) rather than project-scale metrics, and proposes actionable guidance for risk assessment and safer deployment of AI-assisted repair tools.
Abstract
Large language models (LLMs) and their agentic frameworks are increasingly adopted to perform development tasks such as automated program repair (APR). While prior work has identified security risks in LLM-generated code, most have focused on synthetic, simplified, or isolated tasks that lack the complexity of real-world program repair. In this study, we present the first large-scale security analysis of LLM-generated patches using 20,000+ GitHub issues. We evaluate patches proposed by developers, a standalone LLM (Llama 3.3 Instruct-70B), and three top-performing agentic frameworks (OpenHands, AutoCodeRover, HoneyComb). Finally, we analyze a wide range of code, issue, and project-level factors to understand the conditions under which generating insecure patches is more likely. Our findings reveal that Llama introduces many new vulnerabilities, exhibiting unique patterns not found in developers' code. Agentic workflows also generate a number of vulnerabilities, particularly when given more autonomy. We find that vulnerabilities in LLM-generated patches are associated with distinctive code characteristics and are commonly observed in issues missing specific types of information. These results suggest that contextual factors play a critical role in the security of the generated patches and point toward the need for proactive risk assessment methods that account for both issue and code-level information.
