Skip to content

Hidden in the Comments: A Context-Injection Attack Surface in Code LLMs

Oct 2026 · 0 citations · 31 references
Computer Science

TL;DR

Findings identify inference-time context injection as a substantial attack surface and motivate provenance-aware training objectives to identify and motivate provenance-aware training objectives.

Abstract

Code large language model (Code LLM) assistants generate code from heterogeneous development contexts, including open files, imported modules, pasted snippets, and comments, much of which may originate from untrusted sources. We investigate whether insecure instructions embedded in such contexts can steer Code LLMs toward vulnerable code without access to model weights or training data. We evaluate ten open-weight Code LLMs spanning 3B--13B parameters, including four base and six instruction-tuned models, across ten web-application weakness classes. We compare completion tasks containing insecure instructions embedded as code comments with benign tasks without malicious instructions. Attack-condition completions contained a medium-or-higher weakness in {\bf 77.4--92.3}\% of cases, compared with {\bf 1.7--5.1}\% in the benign condition. Base and instruction-tuned models averaged 86.5\% and 84.5\% vulnerable outputs, respectively; equivalence testing and three matched model pairs indicated reductions of at most 8.1\% after instruction tuning. Susceptibility showed no clear association with model scale or specialization. Among vulnerable attack outputs, 86.2--91.0\% were rated high or critical, and the effect persisted without the pattern-based detector. Post-generation screening reduced but did not eliminate the risk, the strongest screen leaving roughly one-third undetected. These findings identify inference-time context injection as a substantial attack surface and motivate provenance-aware training objectives.

View source

Similar papers

Book Open access Nov 2026

Securing Software in the Age of Large Language Models

Large Language Models (LLMs) offer new capabilities for software security by interpreting source code and natural-language specifications, and generating plausible code. However, their probabilistic behavior, hallucinations, limited security knowledge, and inconsistent outputs make their direct use non-trivial. This di...

Varun Gadey · 0 citations
Conference Open access Sep 2026

Not All Adversarial Comments Are Equal: A Ranked Empirical Study of Twelve Comment Injection Attacks Against LLM-Based Code Vulnerability Detection

Large language models are increasingly used to detect security vulnerabilities in source code, and prior work has shown that adversarial comments embedded in the code can suppress detection. What has not been established is whether different categories of adversarial comment differ in effectiveness, and which are most...

Sunny Chokshi · 0 citations
Preprint Oct 2026

Secure and Functional Code Generation with Self-Evaluation

SecGent is presented, an inference-time framework that retrieves weakness context from the Common Weakness Enumeration (CWE) database and applies it to secure code generation and achieves the highest joint functional--security success against four inference-time baselines for all five models.

Md Afif Al Mamun, Gias Uddin · 0 citations
Review Oct 2026

Making Small Code LLMs More Efficient for Secure Code Review with Neuro-Symbolic Fine-Tuning

As AI coding assistants generate more code, the need to review it for security flaws grows. Existing approaches leave a gap: static analyzers identify program sites but offer little explanation, while language-model explanations can be difficult to verify. Small open-weight code models could make security review availa...

Mostafijur Rahman Akhond, Mahmuda Khatun, Gias Uddin · 0 citations
Review Open access Oct 2026

A Review of Source Code Vulnerability Detection Methods Based on Large Language Models: Models, Techniques, and Evaluation

An application approach centered on data governance, strict data splitting, uncertainty calibration, and SAST-LLM-human collaboration is discussed, limited to source-code-level vulnerability detection, localization, and classification.

Le Qin · 0 citations
Conference Open access Sep 2026

Analyze the Code, Not the Comments: Comment-Stripped Analysis Fully Defends LLM-Based Code Vulnerability Detectors Against Adversarial Comment Injection

Large language models are increasingly used to detect security vulnerabilities in source code, but recent work has shown that adversarial comments embedded in the code under review can suppress detection, causing a model to miss genuine vulnerabilities. Because these attacks operate entirely through natural-language co...

Sunny Chokshi · 0 citations

Related blog posts

MIT News · Artificial Intelligence Nov 17, 2026

Learning the language of machine learning

By studying the computational foundations of language learning, Associate Professor Jacob Andreas builds intelligent systems that can communicate effectively with humans.

Microsoft Research Blog Nov 16, 2026

TokenEconomizer: Learning from Experience to Make AI Coding Agents More Efficient

AI coding agents are increasingly help developers fix bugs and build features largely on their own, but every interaction with their models consumes tokens. In each session, an agent sends instructions, tool descriptions, and session history to its model. Most efforts to reduce this cost focus on individual tasks. Yet developers return to the same […] The post TokenEconomizer: Learning from Experience to Make AI Coding Agents More Efficient appeared first on Microsoft Research.

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.