arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2601.07084cs.CRcs.SE
收藏

生成安全代码的安全性如何?对抗性提示对LLM防御进行了测试

How Secure is Secure Code Generation? Adversarial Prompts Put LLM Defenses to the Test

University of Luxembourg(卢森堡大学)

Melissa Tessa, Iyiola E. Olatunji, Aicha War, Jacques Klein, Tegawendé F. Bissyandé

AI总结:

本文评估了生成安全代码方法在对抗性条件下的鲁棒性,发现现有方法在安全性和功能性上存在显著缺陷,提出改进最佳实践。

摘要:

最近的生成安全代码方法,使用漏洞感知的微调、前缀微调和提示优化,声称可以防止LLM生成不安全的代码。然而,它们在对抗性条件下的鲁棒性仍未经过测试,当前的评估将安全性和功能性分开,可能夸大了报告的收益。我们提出了对当前最先进的安全代码生成方法(SVEN、SafeCoder、PromSec)的首次系统性对抗审计。我们对它们施加现实的提示扰动,如改写、提示反转和上下文操纵,这些可能是开发人员无意中引入或对手故意利用的。为了实现公平比较,我们在一致的条件下评估所有方法,使用多个分析器和可执行测试共同评估安全性和功能性。我们的发现揭示了关键的鲁棒性缺口:静态分析器对安全性的估计夸大了7到21倍,其中37到60%的“安全”输出是不具功能性的。在对抗性条件下,真正安全且功能性的比率降至3到17%。基于这些发现,我们提出了构建和评估鲁棒安全代码生成方法的最佳实践。我们的代码已提供。

英文摘要:

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.

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

↑