arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2611.06294cs.CRcs.AIcs.SE
收藏

A.S.E 2.0:探究仓库上下文如何影响大语言模型生成代码的安全性

A.S.E 2.0: Understanding How Repository Context Impacts the Security of LLM-Generated Code

Nanyang Technological University(南洋理工大学);Tencent(腾讯);Zhejiang University(浙江大学)

Jiongchi Yu, Keke Lian, Junqing Wang, Zhikang Fan, Zhaoxuan Li, Yongheng Huang, Ziming Zhao, Dong Zhang

AI总结:

该研究构建CASE-Bench基准,对比多种上下文构建方法与LLM,发现仓库上下文对LLM生成代码的安全通过率影响显著,为安全感知的上下文构建提供依据。

摘要:

大语言模型(LLM)编码助手和智能体在生成代码前会构建仓库上下文。对于安全敏感型代码,该上下文决定模型是否能看到项目的安全防护措施(如授权检查)或可模仿的不安全代码。然而,上下文构建几乎仅针对功能正确性设计,而安全代码基准将上下文视为固定值,因此仓库上下文如何影响生成代码的安全性仍不明确。我们构建了CASE-Bench,这是一个包含51个项目中145个来自真实CVE的仓库级任务的基准。每个任务在Docker中运行,具备功能测试和双向验证的概念验证漏洞利用程序,并标注了可增强或破坏其安全性的仓库代码。利用CASE-Bench,我们比较了13种上下文构建方法、6种对照方法与6种LLM,编辑单个上下文元素,并分析编码智能体的轨迹。我们发现:(1)面向功能的上下文使功能通过率提高了最多8.2个百分点(pp),但安全通过率最多提高了3.7个百分点;(2)隐藏安全防护措施会使安全通过率降低最多8.1个百分点,而插入一个不安全示例会使“正确但可被利用”的代码增加6.3个百分点;(3)编码智能体仅在27%-36%的轨迹中观察到相关安全防护措施。这些发现为安全感知的上下文构建和安全代码评估提供了参考。

英文摘要:

Large language model (LLM) coding assistants and agents construct a repository context before generating code. For security-sensitive code, this context decides whether the model sees the project's safeguards (e.g., authorization checks) or insecure code to imitate. However, context construction is designed almost exclusively for functional correctness, and secure-code benchmarks treat the context as fixed, so how repository context affects the security of generated code remains unclear. We construct CASE-Bench, a benchmark of 145 repository-level tasks from real CVEs in 51 projects. Each task runs in Docker, has functional tests and a proof-of-concept exploit validated in both directions, and is annotated with the repository code that enforces or undermines its security. Using CASE-Bench, we compare 13 context construction methods and six controls with six LLMs, edit single context elements, and analyze coding-agent trajectories. We find that (1) functionality-oriented context raises the functional pass rate by up to 8.2 percentage points (pp) but the secure pass rate by at most 3.7 pp, (2) withholding a safeguard lowers the secure pass rate by up to 8.1 pp, while one inserted insecure exemplar raises correct-but-exploitable code by 6.3 pp, and (3) coding agents observe the relevant safeguard in only 27-36% of trajectories. These findings inform security-aware context construction and secure-code evaluation.

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

↑