[论文解读] CodeLMSec Benchmark: Systematically Evaluating and Finding Security Vulnerabilities in Black-Box Code Language Models
本文提出了CodeLMSec基准测试,一种自动化方法,可系统性地识别触发黑盒代码大语言模型生成漏洞代码的提示词。通过少样本提示近似模型反演,作者生成了可迁移的非安全提示词,暴露了CodeGen和ChatGPT等模型中的安全弱点,生成了一个包含超过2,000个漏洞代码样本的公开基准测试,用于安全评估。
Large language models (LLMs) for automatic code generation have achieved breakthroughs in several programming tasks. Their advances in competition-level programming problems have made them an essential pillar of AI-assisted pair programming, and tools such as GitHub Copilot have emerged as part of the daily programming workflow used by millions of developers. The training data for these models is usually collected from the Internet (e.g., from open-source repositories) and is likely to contain faults and security vulnerabilities. This unsanitized training data can cause the language models to learn these vulnerabilities and propagate them during the code generation procedure. While these models have been extensively assessed for their ability to produce functionally correct programs, there remains a lack of comprehensive investigations and benchmarks addressing the security aspects of these models. In this work, we propose a method to systematically study the security issues of code language models to assess their susceptibility to generating vulnerable code. To this end, we introduce the first approach to automatically find generated code that contains vulnerabilities in black-box code generation models. To achieve this, we present an approach to approximate inversion of the black-box code generation models based on few-shot prompting. We evaluate the effectiveness of our approach by examining code language models in generating high-risk security weaknesses. Furthermore, we establish a collection of diverse non-secure prompts for various vulnerability scenarios using our method. This dataset forms a benchmark for evaluating and comparing the security weaknesses in code language models.
研究动机与目标
- 解决代码生成型大语言模型中安全漏洞缺乏系统性评估方法的问题。
- 开发一种自动化方法,识别能诱导模型生成特定安全缺陷代码的提示词。
- 创建可迁移、可扩展的非安全提示词基准测试,用于评估和比较模型安全性。
- 实现对代码大语言模型在生成高风险漏洞方面脆弱性的大规模、可复现评估。
- 通过公开数据集支持未来研究,提升AI辅助代码生成的安全性。
提出的方法
- 通过少样本提示近似黑盒代码生成模型的反演,生成能诱发目标漏洞的提示词。
- 利用包含漏洞代码及其对应提示词的上下文示例,引导模型充当自身反演的代理。
- 通过CodeQL进行静态分析,自动检测生成代码中的安全漏洞。
- 从多个CWE类别和编程语言中收集并整理多样化的非安全提示词数据集。
- 在CodeGen和ChatGPT等模型之间评估提示词的可迁移性,以验证泛化能力。
- 从多样化来源为每个CWE收集多个漏洞代码样本,以减少提示词生成中的偏差。
实验结果
研究问题
- RQ1我们能否自动生成提示词,系统性地触发代码大语言模型生成漏洞代码?
- RQ2少样本提示在近似黑盒代码生成模型反演方面有多有效?
- RQ3生成的非安全提示词是否可在不同代码大语言模型之间实现可迁移性?
- RQ4该方法能否扩展至识别和基准测试多种类型的安全漏洞?
- RQ5该基准测试在多大程度上实现了模型安全性的可复现和系统性评估?
主要发现
- 该方法成功使用自动推导的提示词,在CodeGen和ChatGPT上生成了超过2,000个漏洞代码样本。
- 非安全提示词具有高度可迁移性,例如来自ChatGPT的提示词能有效触发CodeGen中的漏洞。
- 该基准测试包含覆盖多种CWE类别和编程语言的多样化提示词,支持广泛的安全评估。
- 使用CodeQL进行静态分析能可靠检测出简短、自包含代码片段中的漏洞,确保了可复现性。
- 该方法实现了可扩展、自动化且可扩展的安全基准测试,无需访问模型内部结构或微调。
- 公开发布数据集支持未来对安全代码生成的持续评估与改进。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。