[Paper Review] CodeLMSec Benchmark: Systematically Evaluating and Finding Security Vulnerabilities in Black-Box Code Language Models
This paper introduces CodeLMSec Benchmark, an automated method to systematically identify prompts that trigger black-box code language models into generating vulnerable code. By approximating model inversion via few-shot prompting, the authors generate transferable non-secure prompts that expose security weaknesses across models like CodeGen and ChatGPT, producing a publicly available benchmark of over 2,000 vulnerable code samples for security evaluation.
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.
Motivation & Objective
- To address the lack of systematic evaluation methods for security vulnerabilities in code-generating large language models.
- To develop an automated approach for identifying prompts that induce models to generate code with specific security flaws.
- To create a transferable, scalable benchmark of non-secure prompts for evaluating and comparing model security.
- To enable large-scale, reproducible assessment of code LLMs' susceptibility to generating high-risk vulnerabilities.
- To support future research in improving the security of AI-assisted code generation through a publicly available dataset.
Proposed method
- Approximate inversion of black-box code generation models using few-shot prompting to generate prompts that elicit target vulnerabilities.
- Use in-context examples of vulnerable code and corresponding prompts to guide the model into acting as its own inverse.
- Apply static analysis via CodeQL to automatically detect security vulnerabilities in generated code.
- Collect and curate a diverse dataset of non-secure prompts from multiple CWEs and programming languages.
- Evaluate transferability of prompts across models such as CodeGen and ChatGPT to validate generalization.
- Use multiple vulnerable code samples per CWE from diverse sources to reduce bias in prompt generation.
Experimental results
Research questions
- RQ1Can we automatically generate prompts that systematically trigger code language models to produce vulnerable code?
- RQ2How effective is few-shot prompting in approximating the inverse of a black-box code generation model?
- RQ3Are the generated non-secure prompts transferable across different code LLMs?
- RQ4Can the proposed method scale to identify and benchmark diverse types of security vulnerabilities?
- RQ5To what extent does the benchmark enable reproducible and systematic evaluation of model security?
Key findings
- The method successfully generated over 2,000 vulnerable code samples across CodeGen and ChatGPT using automatically derived prompts.
- The non-secure prompts are highly transferable, with prompts from one model (e.g., ChatGPT) effectively triggering vulnerabilities in another (e.g., CodeGen).
- The benchmark includes diverse prompts covering multiple CWEs and programming languages, enabling broad security evaluation.
- Static analysis with CodeQL reliably detected vulnerabilities in short, self-contained code snippets, ensuring reproducibility.
- The approach enables scalable, automated, and extensible security benchmarking without requiring model internals or fine-tuning.
- The public release of the dataset supports ongoing evaluation and improvement of secure code generation in future models.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.