On Fixing Insecure AI-Generated Code through Model Fine-Tuning and Prompting Strategies
Ali Soltanian Fard Jahromi, Amjed Tahir, Peng Liang, Foutse Khomh
TLDR
This paper systematically investigates strategies for fixing insecure AI-generated code, revealing no universal solution and high dependency on strategy/model.
Key contributions
- Systematically investigates fine-tuning and prompting strategies to fix insecure AI-generated code.
- Assesses security improvements against CWEs across models and programming languages.
- Analyzes severity, co-occurrence, and unintended consequences of security fixes.
- Concludes that no strategy consistently eliminates weaknesses, often introducing new ones.
Why it matters
This paper is crucial as it systematically addresses the significant challenge of insecure AI-generated code, a major barrier to its adoption. It reveals the complexity of fixing these issues, showing that current strategies are highly context-dependent and can introduce new vulnerabilities. This work guides future efforts in developing more robust and secure AI code generation.
Original Abstract
The security of AI-generated code remains a major obstacle to its widespread adoption. Although code generation models achieve strong performance on functional benchmarks, their outputs frequently contain bugs and security weaknesses that undermine their trustworthiness. Prior work has explored a range of approaches to mitigate security issues in AI-generated code, e.g., using static analysis-guided generation and prompt engineering. However, their effectiveness varies widely across models and settings. This paper presents a systematic investigation of strategies for hardening model-generated code against a list of Common Weakness Enumeration (CWE). We assess the extent to which these strategies improve security across models and programming languages, using fine-tuning and prompting approaches for model output refinement. Beyond the prevalence of security weaknesses, we analyse the severity of identified CWEs, their co-occurrence, and the unintended consequences of remediation (i.e., whether fixing certain weaknesses introduces new weaknesses elsewhere in the same code). Our results show that security improvements are highly strategy- and model-dependent. Although some approaches reduce specific classes of weaknesses, they often introduce new weaknesses as side effects of the fixes. Moreover, no strategy consistently eliminates weaknesses across all models and scenarios, highlighting the absence of a universally effective "bulletproof" solution for secure AI-generated code.
📬 Weekly AI Paper Digest
Get the top 10 AI/ML arXiv papers from the week — summarized, scored, and delivered to your inbox every Monday.