安全代码生成有多安全?对抗性提示让LLM防御面临考验 How Secure is Secure Code Generation? Adversarial Prompts Put LLM Defenses to the Test 预印本

⚠️ 本文为 预印本(arXiv 公开版本),尚未经过正式同行评审。作者自发公开,结论未经期刊审稿验证,阅读时请知悉。
发布时间:2026-01-11
👁️ 预览文献
💡 AI 中文简介
研究测试了三种主流安全代码生成方法(SVEN、SafeCoder、PromSec)在对抗性提示下的鲁棒性。通过改写、线索反转和上下文操纵等扰动,发现静态分析器高估安全性7-21倍,37-60%的“安全”输出无法运行,真正安全且可运行的比例仅3-17%。研究揭示了现有方法的严重缺陷,并提出了改进建议。
领域软件工程 / 代码生成与安全
适合谁读需要一定专业背景(了解LLM和代码安全基础)
核心贡献首次对最先进的安全代码生成方法进行系统性对抗审计,揭示了静态分析器高估安全性和功能正确性缺失的问题;提出了构建和评估鲁棒安全代码生成方法的最佳实践。
关键数据静态分析器高估安全性7-21倍;37-60%的“安全”输出无法运行;对抗条件下真正安全且可运行的比例降至3-17%。
推荐理由如果你关心AI生成的代码是否真的安全,这项研究用硬数据揭示了现有防御的脆弱性,值得一读。
关键词["安全代码生成", "对抗性提示", "大语言模型", "鲁棒性评估", "静态分析", "功能正确性"]

原文摘要

查看英文原文摘要

Recent secure code generation methods, using vulnerability-aware fine-tuning, prefix-tuning, and prompt optimization, claim to prevent LLMs from producing insecure code. However, their robustness under adversarial conditions remains untested, and current evaluations decouple security from functionality, potentially inflating reported gains. We present the first systematic adversarial audit of state-of-the-art secure code generation methods (SVEN, SafeCoder, PromSec). We subject them to realistic prompt perturbations such as paraphrasing, cue inversion, and context manipulation that developers might inadvertently introduce or adversaries deliberately exploit. To enable fair comparison, we evaluate all methods under consistent conditions, jointly assessing security and functionality using multiple analyzers and executable tests. Our findings reveal critical robustness gaps: static analyzers overestimate security by 7 to 21 times, with 37 to 60% of ``secure'' outputs being non-functional. Under adversarial conditions, true secure-and-functional rates collapse to 3 to 17%. Based on these findings, we propose best practices for building and evaluating robust secure code generation methods. Our code is available.