Securing AI Code Generation Through Automated Pattern-Based Patching
In an era where AI code generators are reshaping software development, the risk of introducing vulnerabilities is a growing concern. With the increasing reliance on machine learning-driven tools, it is essential to support developers with effective automated vulnerability patching while prioritizing the reliability and security of AI. However, current methods face significant challenges, including a high rate of false positives and difficulties in generating high-quality patches. This paper presents PatchitPy, a new patching solution that leverages a pattern-matching approach to detect and patch Python vulnerabilities. We generated 609 Python code using three popular AI code generators (i.e., GitHub Copilot, Claude-3.7-Sonnet, and DeepSeek- V3)and evaluated our solution's performance on these samples. The results demonstrate the effectiveness of PatchitPy, which outperforms state-of-the-art solutions in both detection and patching. PatchitPy achieved an F<inf xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">1</inf> score of 93% and an Accuracy of 89% for vulnerability detection, and produced high-quality patches with a 80% repair rate for identified vulnerabilities. Furthermore, the patches preserve code quality with minimal impact on complexity, ensuring long-term code maintainability.
Authors
- Domenico Cotroneo (ORCID: https://orcid.org/0000-0001-7103-592X)
- Pietro Liguori (ORCID: https://orcid.org/0000-0001-5579-1696)
- Francesco Altiero (ORCID: https://orcid.org/0000-0001-7090-4249)
- Roberta De Luca (ORCID: https://orcid.org/0009-0005-2938-5551)
Institutions
- University of Naples Federico II (IT)
Publication Details
- Published
- 2025-06-23
- DOI
- https://doi.org/10.1109/dsn-w65791.2025.00077
- Citations
- 2
- Primary Topic
- Advanced Malware Detection Techniques
- Type
- article
- Field-Weighted Citation Impact
- 2.97