Paper commentary
A.S.E 2.0: Understanding How Repository Context Impacts the Security of LLM-Generated Code
Repository context decides whether LLM-written code is secure
- Problem Secure-code benchmarks treat repository context as fixed, so it is unclear how context changes the security of generated code.
- Method CASE-Bench holds the task and tests fixed and varies only the repository context, using 145 tasks from real CVEs.
- Results Functionality-oriented context methods raise the secure pass rate by at most 3.7 pp over Local-only context.

Figure 2 : Overview ofCASE-Bench: construction (top), the model–evaluation information barrier (middle), and controlled evaluation (bottom).⋆marks properties compared with prior benchmarks in §7.
Original paper · CC BY 4.0 · Jiongchi Yu, Keke Lian, Junqing Wang, Zhikang Fan, Zhaoxuan Li, Yongheng Huang, Ziming Zhao, Dong Zhang · A.S.E 2.0: Understanding How Repository Context Impacts the Security of LLM-Generated Code · Original paper figure · Extracted the figure area from page 4 of the original PDF.Why repository context can hurt security
Coding assistants and agents seldom write code from the prompt alone, because they first assemble context from the repository. That context decides what the model sees, and for security the protective check is often not local. Context construction therefore also decides whether the model sees the repository's security policy, and it can expose legacy code with the same weakness.
Figure 1 walks through CVE-2021-20205, a divide-by-zero bug in the GIF reader of libjpeg-turbo. The requirement asks for parsing the image dimensions but never mentions that they may be zero. The other image readers in the same repository reject zero dimensions, so the project already holds the check.

Figure 1 : CVE-2021-20205. (a) Sibling image readers check for zero dimensions; the GIF reader does not. (b, c) With the model, task, and prompt fixed, ① four contexts yield correct-but-exploitable code, whereas ② ReACC-Hybrid retrieves the Targa guard and③the generated code reproduces it. Outcomes hold across all runs.
Original paper · CC BY 4.0Existing secure-code benchmarks treat context as fixed, so they can't explain how it affects security. Most of them judge security with static rules or LLM judges, which miss runtime-dependent weaknesses.
The paper frames four candidate mechanisms as hypotheses, and it treats a unit that enforces the policy as a safeguard that can help. A unit that violates the policy, such as an unfixed sibling, can hurt by pulling the model toward imitation. Long contexts can also bury a safeguard, which is the dilution mechanism. Security-themed text that doesn't apply to the target may change the output by itself, which confounds the evaluation of security-aware methods.
How CASE-Bench isolates the context
CASE-Bench starts from 145 repository-level tasks, derived from 144 real CVEs in 51 open-source projects. The tasks cover 28 CWEs in seven languages, and they range from generic checks to project-specific policies. Each task fixes a repository at its last vulnerable commit and masks one region of a target file. Because the task, prompt and oracle stay fixed, only the context changes between runs.
Ten security experts built the set in five steps, and two of them performed each manual step independently. The team screened 1,236 records, and 488 passed a filter that drops fixes changing more than ten files. The team admitted 144 CVEs, which give 145 tasks, and most rejections came from build failures, PoCs that did not reproduce, or vulnerable code with no coherent region.
An expert wrote a requirement that names no attack or defense, and two experts audited the LLM-drafted requirements and rewrote 23 of them.
It never sees the CVE identifier, the fix or the evaluation tests. Because that snapshot precedes the fix, it can contain insecure exemplars, which the authors kept and annotated in 74 tasks. Each generation runs in a fresh container through a build check, the functional tests and a PoC replay.
All 145 vulnerable versions pass the tests and let the PoC succeed, and all 145 patched versions pass the tests and block it. An independent reviewer wrote an alternative secure implementation before seeing the patch, and it passed in 143 of 145 tasks. This alternative checks that the oracles don't simply fit the historical fix, and it checks solvability within the edit scope.
The manual audit agreed with the verdicts on 95.7% of generations. The deny-all implementation fails the tests in all 145 tasks, so correctness can't be met by refusing the task.
Thirteen context methods on one task
The context effect is the secure rate of a method on a task minus the secure rate of Local-only on that same task. Written out, Δ(s,t) equals SecRate(s,t) minus SecRate(Local-only,t), where s is the method and t is the task. Because each run is either secure or not, the paper treats differences in Δ as attributable to the context when everything else is held fixed.
Differences over three runs still contain sampling noise, so the authors test them statistically rather than reading them directly.
The study compares eleven functionality-oriented methods that cover all major retrieval families. Those families are similarity, in-file, structure and agentic retrieval, and Table 2 lists each policy as reproduced. The authors also add two security-aware methods, CodeGuarder and Source-sink slicing. Source-sink slicing follows data flow from untrusted input to a sensitive operation and keeps the guards on that path.
It uses only the generic CodeQL and Joern models, so it never sees the oracle's queries. Every method runs in one common pipeline with an 8K retrieval cap, and each keeps its own ranking logic and hyperparameters. The cap doesn't equalize length or cost, so the authors report actual sizes in Table 2.

Table 2 : Context construction methods and conditions. “Gen.-dep. ”: the context depends on the generator model. “Tokens”: mean context size beyond the masked target file, at the 8K retrieval cap (Repo-128K: 128K). “Fix-API”: mean fraction of fix-relevant APIs whose definitions are in the prompt, including the masked target file (hence non-zero for Local-only).
Original paper · CC BY 4.0Six controls separate the effect of context from other causes. Local-only shows the masked target file alone and serves as the reference for every context effect. BM25+README is the configuration of A.S.E, which anchors the results to a prior evaluation. Repo-128K serializes the visible repository outward from the target's directory and truncates it to fit the smallest window, so it is a truncated repository.
The Reference context holds exactly the annotated safeguards and the source-sink path, and the authors call it a diagnostic rather than an upper bound.
Six generator LLMs run the study, three proprietary and three open-weight, each with three runs per task. SecPass@1 is the primary metric, and CbE@1 is the primary risk metric. FuncPass@1 equals SecPass@1 plus CbE@1, so the three rates stay linked. The RQ1 comparison alone produces 49,590 generations.
Functionality gains don't carry over to security
Four methods even have a lower observed SecPass@1 than Local-only, so the functional gains don't translate into safer code. Between 40.3% and 50.2% of all generations are correct but exploitable, which is the failure mode that the functional pass rate hides. The RealSec-bench observation for Java retrievers holds here, and the paper extends it to all major method families.
ProCC-Multi has the highest FuncPass@1 at 65.1%, yet it ranks only third on SecPass@1. Correct-but-exploitable code makes up 72% of its functional gain, so much of what it adds is working but unsafe code. CCEval-BM25 and Repo-128K raise CbE@1 by more than FuncPass@1, so their extra working code is exploitable on balance. The rankings by FuncPass@1 and by SecPass@1 agree only moderately, with a Kendall tau-b of 0.48.
Security-aware methods do better: CodeGuarder adds 4.2 pp with OR 1.40, and Source-sink adds 5.5 pp with OR 1.53 relative to Local-only. Both methods lower CbE@1 below Local-only, which means they reduce the exploitable share of working code. The Reference context adds 12.2 pp, and Source-sink recovers 4% of the Local-only-to-Reference gain.
The gains depend on the weakness family: on access-control tasks, Source-sink reaches 9.3% SecPass@1, compared to 3.1% for CodeGuarder. Repo-128K raises FuncPass@1 by 4.0 pp but lowers SecPass@1 by 0.5 pp relative to Local-only. So 128K tokens of repository code give no more security than a 4K-token slice.
Which context element moves security
The authors removed one safeguard role at a time from the Reference context, and each removal lowered the secure pass rate. Removing the safe API lowers SecPass@1 by 8.1 pp, removing a validator by 6.7 pp, the policy by 5.2 pp and the caller contract by 3.9 pp. Because length and position explain little of the effect, the removed content itself carries the change.
Most lost secure outputs, 56 to 62%, become correct but exploitable, so part of the effect runs through functionality.
The authors then inserted one natural insecure exemplar into the Reference context, on the 74 tasks that contain one. The insertion raises CbE@1 by 6.3 pp even though the safeguard remains present in the context.
For ReACC-Hybrid, SecPass@1 rises from 13.5% with Local-only to 16.6% at 8K tokens. Beyond 8K tokens, SecPass@1 falls to 14.6% at 32K, even though its fix-API recall still grows. Over that range the share of contexts holding an insecure exemplar climbs from 41% to 90%, while security density drops from .19 to .06. The authors tie the decline to more exemplars rather than to lower recall, and DevEval-Dep and RepoCoder-Iter already peak at 4K tokens.
Failure labels show how the correct-but-exploitable code shifts when the context changes. Per 100 generations, Missing falls from 20.6 to 12.3, while Unused and Misused together rise from 10.7 to 21.3. The authors stress that these labels describe co-occurrence rather than cause, and their precision ranges from .72 to .94.
Coding agents rarely look for safeguards
The agent study runs SWE-agent on two backbones and Claude Code, and agents may edit only the masked region. The relevant safeguard was observed in 29% of SWE-agent trajectories with Sonnet 4.5, 27% with GPT-5.4 and 36% with Claude Code. Most of their search queries target functionality rather than security.
The agent barely beats the retrieval method on security while seeing far more repository code, and observed tokens accumulate over a trajectory rather than measuring one prompt.
Trajectories that observed an insecure exemplar produced more correct-but-exploitable code, 61.6% compared to 48.4%. Trajectories that observed the safeguard were more often secure. The agent analysis is observational, so these are associations rather than controlled effects.
Does the oracle change the ranking?
The authors check whether their conclusions depend on the security oracle by comparing static analysis with the base PoC. It misses 40% of exploited generations, for example off-by-one bounds checks.
The authors conclude that comparative conclusions about context methods depend on the oracle. A static-only evaluation would have credited methods whose code merely contains defensive patterns.
The OpenEMR case, CVE-2022-2732 at CWE-862 and level L3, shows what the policy looks like in a real repository. The required permission sits only in a widget guard in demographics.php, and the requirement never mentions it. Similarity retrieval favoured the unchecked siblings, so the generated code imitated them.
CodeGuarder's generic advice produced checks for only a login or for administrator rights, and the latter rejected the legitimate clinician in 1/18 runs. ClaudeCode-Ret retrieved demographics.php but ranked it after the siblings, so it helped in 3/18 runs.
Where the limitations of the A.S.E 2.0 results stop
A PoC can show that an exploit works but can't rule out every vulnerability, so SecPass@1 only holds relative to the tests and exploits used.
The failure labels are heuristic, with label precision from .72 (Imitated) to .94 (Missing). The static oracle uses a single query configuration, so the authors don't claim it covers every static analysis setup. The power analysis on a pilot run gave 80% power only for 5.6 pp after correction. A nonsignificant result therefore doesn't establish the absence of an effect, so smaller effects may go undetected.
Six projects contribute 67 tasks, so the project is the unit of clustering and reweighting projects is a key check. Task characteristics such as weakness type and language remain partly confounded with the project effects.
The reproduced context policies may deviate from the original systems, especially in newly supported languages.
Paper info
- Authors
- Jiongchi Yu, Keke Lian, Junqing Wang, Zhikang Fan, Zhaoxuan Li, Yongheng Huang, Ziming Zhao, Dong Zhang
- Venue
- arXiv · Preprint
- First published
- 2026-11-4
- Added
- 2026-11-6
- Updated
- 2026-11-4
- Version
- v1
- arXiv
- 2611.06294
- Category
- cs.CR · cs.AI · cs.SE
- Original paper terms
- CC BY 4.0
- What we show
- Paper info, commentary and permitted figures from the original paper
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
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 (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.
Quote from the paper
Jiongchi Yu, Keke Lian, Junqing Wang, Zhikang Fan, Zhaoxuan Li, Yongheng Huang, Ziming Zhao, Dong Zhang (2026). A.S.E 2.0: Understanding How Repository Context Impacts the Security of LLM-Generated Code. arXiv:2611.06294v1. https://arxiv.org/abs/2611.06294v1
BibTeX
@misc{yu2026understanding,
title = {{A.S.E 2.0: Understanding How Repository Context Impacts the Security of LLM-Generated Code}},
author = {Jiongchi Yu and Keke Lian and Junqing Wang and Zhikang Fan and Zhaoxuan Li and Yongheng Huang and Ziming Zhao and Dong Zhang},
year = {2026},
eprint = {2611.06294},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2611.06294v1}
}