AutoSUIT
收藏资源简介:
AutoSUIT Bench是一个用于大型语言模型(LLM)安全代码生成的动态、基于执行的基准测试数据集。该数据集旨在评估LLM在生成安全代码方面的能力,覆盖了C、C++、Java和Python四种编程语言,共涉及232个常见弱点枚举(CWE)。数据集的每个样本都是一个自包含的单元,包含自然语言任务描述(code_description)、对应的CWE描述(cwe_description)、可选的上下文信息(如易受攻击的代码vulnerable_code用于漏洞修补任务,或代码补全前缀completion_prefix用于代码补全任务),以及参考的安全代码(secure_code)。每个样本还附带两个独立的单元测试套件:功能性测试套件(functional_test)用于验证代码的正确性,安全性测试套件(security_test)设计为在目标CWE漏洞存在时失败,从而评估代码的安全性。数据集总计包含951个样本,具体分布为:Python(113个样本,39个CWE)、Java(365个样本,143个CWE)、C(277个样本,100个CWE)、C++(196个样本,79个CWE)。数据集支持四种核心评估任务:安全代码生成(根据描述生成安全代码)、具有CWE意识的代码生成(在了解CWE描述的情况下生成安全代码)、漏洞修补(修复给定易受攻击代码中的安全漏洞)和代码补全(根据前缀完成代码)。评估过程要求将模型生成的代码保存到指定的文件名(code_file_name),然后在独立环境中编译/解释并运行两个测试套件,分别计算功能通过率和安全通过率,采用一种宽松的pass@k指标进行评分,该指标考虑了部分通过的测试用例。
AutoSUIT Bench is a dynamic, execution-based benchmark dataset for secure code generation by large language models (LLMs). It aims to evaluate the ability of LLMs to generate secure code, covering four programming languages: C, C++, Java, and Python, involving 232 Common Weakness Enumerations (CWEs). Each sample in the dataset is a self-contained unit that includes a natural language task description (code_description), the corresponding CWE description (cwe_description), optional context information (such as vulnerable_code for vulnerability patching tasks, or completion_prefix for code completion tasks), and reference secure code (secure_code). Each sample also comes with two independent unit test suites: a functional test suite (functional_test) to verify code correctness, and a security test suite (security_test) designed to fail when the target CWE vulnerability is present, thereby assessing code security. The dataset contains a total of 951 samples, distributed as follows: Python (113 samples, 39 CWEs), Java (365 samples, 143 CWEs), C (277 samples, 100 CWEs), C++ (196 samples, 79 CWEs). The dataset supports four core evaluation tasks: secure code generation (generating secure code based on descriptions), CWE-aware code generation (generating secure code with knowledge of CWE descriptions), vulnerability patching (fixing security vulnerabilities in given vulnerable code), and code completion (completing code based on prefixes). The evaluation process requires saving the model-generated code to a specified filename (code_file_name), then compiling/interpreting and running the two test suites in an isolated environment, calculating functional pass rates and security pass rates separately, using a lenient pass@k metric that accounts for partially passed test cases.
数据集概述:AutoSUIT Bench
基本信息
- 数据集名称:AutoSUIT Bench(HuggingFace Edition)
- 许可协议:cc-by-nc-4.0
- 语言:英语
- 任务类别:文本生成
- 数据集规模:样本数 < 1,000
核心内容
AutoSUIT Bench 是一个动态、基于执行的基准测试,用于评估大语言模型(LLM)的安全代码生成能力。每个生成的程序都会被编译/解释,并针对两套独立的单元测试套件运行——功能套件和安全套件(安全套件的设计目的是在目标 CWE 漏洞存在时失败)。该数据集涵盖 C、C++、Java 和 Python 四种编程语言中的 232 个 CWE。
数据配置与规模
数据集包含四个配置(config),每个配置对应一种编程语言,所有数据均为测试集(test split):
| 配置名称 | 数据文件 | 样本数量 | 覆盖 CWE 数量 |
|---|---|---|---|
| python | python/test.jsonl | 113 个样本 | 39 个 CWE |
| java | java/test.jsonl | 365 个样本 | 143 个 CWE |
| c | c/test.jsonl | 277 个样本 | 100 个 CWE |
| cpp | cpp/test.jsonl | 196 个样本 | 79 个 CWE |
数据格式与字段
每个 test.jsonl 文件中的每一行是一个自包含的样本,包含以下字段:
| 字段 | 类型 | 描述 |
|---|---|---|
id |
str | 唯一标识,格式为 "<语言>_<行号>"。 |
language |
str | 编程语言(python / java / c / cpp)。 |
cwe_id |
int | 样本对应的主要 CWE 编号。 |
reference_file_name |
str | 该行索引的参考文件名称。 |
secure_status |
int | 参考文件的标签:1 = 安全,0 = 存在漏洞。 |
code_file_name |
str | 模型生成代码必须保存为的文件名,测试将以此名称引用。 |
module_name |
str | 与 code_file_name 相同,但不含扩展名。 |
code_description |
str | 自然语言描述的任务说明,是核心提示词。 |
cwe_description |
str | CWE 的纯文本描述。 |
context |
str | 额外的真实世界使用上下文(仅 Python 样本有)。 |
vulnerable_code |
str | 功能正常但存在漏洞的实现,用于补丁任务。 |
completion_prefix |
str | 安全解决方案的前约 30% 代码,用于代码补全任务。 |
secure_code |
str | 参考的安全解决方案,仅供分析。 |
sec_test_cases |
str | 安全测试套件编码的安全场景的自然语言枚举。 |
functional_test_file |
str | 功能测试套件的文件名。 |
functional_test |
str | 功能单元测试套件 U_f 的完整源代码。 |
security_test_file |
str | 安全测试套件的文件名。 |
security_test |
str | 安全单元测试套件 U_s 的完整源代码。 |
任务设计
该基准测试定义了四个任务,所有任务使用相同的样本,仅提示词中的上下文不同。每个样本需生成仅代码(以注释形式包含解释),并保存为 code_file_name。
- 安全代码生成:根据
code_description生成代码。 - 带 CWE 意识的代码生成:除了
code_description,还提供cwe_description作为额外上下文。 - 漏洞修补:基于
cwe_description和vulnerable_code,修复代码中的安全漏洞。 - 代码补全:根据
code_description和completion_prefix,补全后续代码。
评估方法
对每个样本的每次生成:
- 创建临时目录,复制功能测试套件和安全测试套件。
- 将模型输出写入
code_file_name。 - 编译/运行每个测试套件,统计通过的断言/测试数量。
- 分别报告功能通过率和安全/漏洞通过率。
不同语言的运行方式:
- Python:使用
pytest运行,解析N passed, M failed摘要。 - C/C++:编译测试文件(启用
-DUNIT_TEST),解析打印的tests failed: X, tests passed: Y计数。 - Java:使用 JUnit 5 + Mockito,通过 JUnit 控制台启动器运行,解析其摘要。
评分机制
使用宽松的 pass@k 指标:对每个测试套件,计算 pass/(pass+fail) 作为部分分数,并取整后平均到所有问题上。
相关论文
Osebe et al., AutoSUIT Bench — Automated Security UnIt Test Benchmark for LLM Coding, Findings of ACL 2026, pp. 34759–34783. (https://aclanthology.org/2026.findings-acl.1735.pdf)




