重新评估代码生成的安全性,发现现有方法常牺牲功能来换安全。
Rethinking the Evaluation of Secure Code Generation
- 统一测试生成代码的安全性与功能性,使用相同数据集。
- 三款静态分析工具+两模型验证,发现性能下降超50%。
- 现有方法常删漏洞代码或生成无关垃圾代码,效果被高估。
大型语言模型在软件开发中广泛应用,但其生成的代码常含漏洞。现有安全代码生成方法的评估方式存在缺陷:安全性和功能正确性通常分开评估,使用不同数据集;且主要依赖单一静态分析工具CodeQL,限制了评估范围。本文系统评估四种前沿安全代码生成技术,将安全检测与功能验证同步应用于同一生成代码,并采用三种主流静态分析工具及两台大模型识别漏洞。结果表明,现有方法为提升安全性常损害代码功能性,整体表现受限;部分技术使基线模型性能下降超过50%。深入分析发现,这些方法常彻底移除漏洞代码或生成与任务无关的垃圾代码。此外,常用分析工具CodeQL未能检测出若干漏洞,导致实际安全提升被严重低估。
原文摘要 · Abstract (English)
Large language models (LLMs) are widely used in software development. However, the code generated by LLMs often contains vulnerabilities. Several secure code generation methods have been proposed to address this issue, but their current evaluation schemes leave several concerns unaddressed. Specifically, most existing studies evaluate security and functional correctness separately, using different datasets. That is, they assess vulnerabilities using security-related code datasets while validating functionality with general code datasets. In addition, prior research primarily relies on a single static analyzer, CodeQL, to detect vulnerabilities in generated code, which limits the scope of security evaluation. In this work, we conduct a comprehensive study to systematically assess the improvements introduced by four state-of-the-art secure code generation techniques. Specifically, we apply both security inspection and functionality validation to the same generated code and evaluate these two aspects together. We also employ three popular static analyzers and two LLMs to identify potential vulnerabilities in the generated code. Our study reveals that existing techniques often compromise the functionality of generated code to enhance security. Their overall performance remains limited when evaluating security and functionality together. In fact, many techniques even degrade the performance of the base LLM by more than 50%. Our further inspection reveals that these techniques often either remove vulnerable lines of code entirely or generate ``garbage code'' that is unrelated to the intended task. Moreover, the commonly used static analyzer CodeQL fails to detect several vulnerabilities, further obscuring the actual security improvements achieved by existing techniques.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。