Manuscript Offprint

arXiv:2611.06294

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

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

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Jiongchi Yu*

jiongchiyu@acm.org

Nanyang Technological University

Singapore, Singapore

Keke Lian*

kekelian@tencent.com

Tencent

China

Zhikang Fan

15030857023@163.com

Zhejiang University

Hangzhou, China

Junqing Wang

wangjunqing388@gmail.com

Zhejiang University

Hangzhou, China

Zhaoxuan Li

lizhaoxuan@iie.ac.cn

IIE, CAS

Beijing, China

Yongheng Huang

yonghenghuang384@gmail.com

Tencent

China

Ziming Zhao†

zhaoziming@zju.edu.cn

Zhejiang University

Hangzhou, China

Dong Zhang†

zalezhang@tencent.com

Tencent

China

Abstract

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 ① 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, ② 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 ③ coding agents observe the relevant safeguard in only 27-36% of trajectories. These findings inform security-aware context construction and secure-code evaluation.

CCS Concepts

• Software and its engineering → Software verification and validation; • Security and privacy → Software and application security.

References (34)