On Fixing Insecure AI-Generated Code through Model Fine-Tuning and Prompting Strategies

Fuente: arXiv
Guardado en:
Detalles Bibliográficos
Autores principales: Jahromi, Ali Soltanian Fard, Tahir, Amjed, Liang, Peng, Khomh, Foutse
Formato: Preprint
Publicado: 2026
Materias:
Acceso en línea:
Etiquetas: Agregar Etiqueta
Sin Etiquetas, Sea el primero en etiquetar este registro!
_version_ 1866909020504195072
author Jahromi, Ali Soltanian Fard
Tahir, Amjed
Liang, Peng
Khomh, Foutse
author_facet Jahromi, Ali Soltanian Fard
Tahir, Amjed
Liang, Peng
Khomh, Foutse
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2605_05867
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle On Fixing Insecure AI-Generated Code through Model Fine-Tuning and Prompting Strategies
Jahromi, Ali Soltanian Fard
Tahir, Amjed
Liang, Peng
Khomh, Foutse
Software Engineering
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.
title On Fixing Insecure AI-Generated Code through Model Fine-Tuning and Prompting Strategies
topic Software Engineering
url https://arxiv.org/abs/2605.05867