arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2605.05867cs.SE
收藏

通过模型微调和提示策略修复不安全的AI生成代码

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

Massey University(梅西大学);Wuhan University(武汉大学);Polytechnique Montréal(蒙特利尔理工大学)

Ali Soltanian Fard Jahromi, Amjed Tahir, Peng Liang, Foutse Khomh

AI总结:

本文系统研究了通过模型微调和提示策略增强AI生成代码安全性的方法,分析了不同策略和模型对安全性的提升效果,发现安全改进高度依赖策略和模型,且修复某些漏洞可能引入新漏洞。

摘要:

AI生成代码的安全性仍是其广泛应用的主要障碍。尽管代码生成模型在功能基准上表现优异,但其输出常包含错误和安全漏洞,影响可信度。本文系统研究了通过微调和提示策略增强代码安全性的方法,评估了不同策略和模型在多种编程语言中的安全提升效果。此外,我们分析了识别出的CWE严重性、共现情况以及修复的意外后果(即修复某些漏洞是否在代码其他部分引入新漏洞)。研究结果表明,安全改进高度依赖策略和模型,尽管某些方法可减少特定漏洞类别,但常导致新漏洞产生。此外,没有策略能一致消除所有模型和场景中的漏洞,凸显了缺乏统一有效“无漏洞”解决方案的现状。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑