arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2407.02395cs.SEcs.CL
收藏

迈向安全代码生成:通过任务自适应漏洞建模和基于执行的基准测试弥合正确性与安全性之间的差距

Toward Secure Code Generation: Bridging Correctness and Security via Task-Adaptive Vulnerability Modeling and Execution-Based Benchmarking

South China University of Technology(华南理工大学);University of Innsbruck(因斯布鲁克大学)

Jiexin Wang, Liuwen Cao, Xitong Luo, Yang Cao, Zhenghao Li, Yunyi Xiao, Mengchen Zhao, Adam Jatowt, Yi Cai

AI总结:

本文提出CodeSecEval基准和SecAwareCoder框架,通过任务自适应威胁建模与执行反馈,提升LLM代码生成的安全性与正确性,实验验证其有效性。

摘要:

大型语言模型(LLMs)越来越多地用于程序合成,但它们生成的代码往往在功能上看似合理,却存在安全隐患。安全代码生成的进展一直受到基准测试的限制,这些基准测试规模小、不可执行、泄露缓解细节,或依赖有噪声的分析器和主观判断,使得难以在不牺牲正确性的前提下衡量安全性是否得到提升。我们通过CodeSecEval来弥补这些不足,这是一个基于执行的安全代码生成基准测试,包含跨越77个CWE类别的255个Python任务。每个任务提供成对的不安全与安全实现,以及可执行的功能测试和针对漏洞的安全测试,从而能够对安全代码生成和不安全代码修复进行精确且可复现的评估。基于CodeSecEval,我们提出了SecAwareCoder,一个基于智能体的框架,将代码生成转向安全优先的合成。SecAwareCoder执行任务自适应威胁建模,以识别安全敏感区域并推导出基于任务的漏洞假设,利用这些假设来指导约束感知的代码生成和安全感知的测试合成,并利用执行反馈进行有针对性的改进。在多个LLM后端的实验表明,SecAwareCoder在Pass@1和安全性鲁棒性方面持续优于提示和基于分析器的基线,缩小了LLM代码生成中安全性与正确性之间的差距。

英文摘要:

Large language models (LLMs) are increasingly used for program synthesis, yet they often generate code that is functionally plausible but insecure. Progress in secure code generation has been hindered by benchmarks that are small, non-executable, leak mitigation details, or rely on noisy analyzers and subjective judgments, making it difficult to measure whether security improves without sacrificing correctness. We address these gaps with CodeSecEval, an execution-based benchmark for secure code generation, comprising 255 Python tasks spanning 77 CWE categories. Each task provides paired insecure and secure implementations together with executable functional and vulnerability-targeted security tests, enabling precise and reproducible evaluation of secure code generation and insecure-code repair. Building on CodeSecEval, we propose SecAwareCoder, an agent-based framework that shifts code generation toward secure-by-construction synthesis. SecAwareCoder performs task-adaptive threat modeling to identify security-sensitive regions and derive task-grounded vulnerability hypotheses, uses these hypotheses to guide both constraint-aware code generation and security-aware test synthesis, and leverages execution feedback for targeted refinement. Experiments across multiple LLM backbones show that SecAwareCoder consistently improves Pass@1 and security robustness over prompting and analyzer-driven baselines, narrowing the security--correctness gap in LLM code generation.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑