Large Language Models (LLMs) have demonstrated remarkable capabilities in code generation, but their proficiency in producing secure code remains a critical, under-explored area. Existing benchmarks often fall short by relying on synthetic vulnerabilities or evaluating functional correctness in isolation, failing to capture the complex interplay between functionality and security found in real-world software. To address this gap, we introduce RealSec-bench, a new benchmark for secure code generation meticulously constructed from real-world, high-risk Java repositories. Our methodology employs a multi-stage pipeline that combines systematic SAST scanning with CodeQL, LLM-based false positive elimination, and rigorous human expert validation. The resulting benchmark contains 105 instances grounded in real-word repository contexts, spanning 19 Common Weakness Enumeration (CWE) types and exhibiting a wide diversity of data flow complexities, including vulnerabilities with up to 34-hop inter-procedural dependencies. Using RealSec-bench, we conduct an extensive empirical study on 5 popular LLMs. We introduce a novel composite metric, SecurePass@K, to assess both functional correctness and security simultaneously. We find that while Retrieval-Augmented Generation (RAG) techniques can improve functional correctness, they provide negligible benefits to security. Furthermore, explicitly prompting models with general security guidelines often leads to compilation failures, harming functional correctness without reliably preventing vulnerabilities. Our work highlights the gap between functional and secure code generation in current LLMs.


翻译:大型语言模型(LLM)在代码生成方面展现出卓越能力,但其生成安全代码的熟练度仍是一个关键且尚未充分探索的领域。现有基准通常存在不足,它们依赖于合成漏洞或孤立地评估功能正确性,未能捕捉真实世界软件中功能与安全性之间复杂的相互作用。为弥补这一空白,我们引入了RealSec-bench,这是一个从真实世界、高风险的Java仓库精心构建的、用于安全代码生成的新基准。我们的方法采用多阶段流程,结合了基于CodeQL的系统性静态应用安全测试(SAST)扫描、基于LLM的误报消除以及严格的人类专家验证。最终构建的基准包含105个基于真实仓库上下文的实例,涵盖19种常见缺陷枚举(CWE)类型,并展现出广泛的数据流复杂性多样性,包括具有多达34跳跨过程依赖的漏洞。利用RealSec-bench,我们对5个流行的LLM进行了广泛的实证研究。我们引入了一个新颖的复合指标SecurePass@K,以同时评估功能正确性和安全性。我们发现,虽然检索增强生成(RAG)技术可以提高功能正确性,但它们对安全性的益处微乎其微。此外,明确提示模型遵循通用安全指南常常导致编译失败,损害功能正确性,却不能可靠地防止漏洞。我们的工作凸显了当前LLM在功能性与安全性代码生成之间的差距。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
生成式人工智能大型语言模型的安全性:概述
专知会员服务
35+阅读 · 2024年7月30日
《大型语言模型代码生成》综述
专知会员服务
70+阅读 · 2024年6月4日
深度学习文本分类方法综述(代码)
中国人工智能学会
28+阅读 · 2018年6月16日
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
最新内容
大语言模型平台在国防情报应用中的对比
专知会员服务
3+阅读 · 今天3:12
美海军“超配项目”
专知会员服务
4+阅读 · 今天2:13
《美陆军条例:陆军指挥政策(2026版)》
专知会员服务
10+阅读 · 4月21日
《军用自主人工智能系统的治理与安全》
专知会员服务
7+阅读 · 4月21日
《系统簇式多域作战规划范畴论框架》
专知会员服务
10+阅读 · 4月20日
相关VIP内容
生成式人工智能大型语言模型的安全性:概述
专知会员服务
35+阅读 · 2024年7月30日
《大型语言模型代码生成》综述
专知会员服务
70+阅读 · 2024年6月4日
相关基金
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员