Poison with Style: A Practical Poisoning Attack on Code Large Language Models

Khang Tran, Yazan Boshmaf, Issa Khalil, NhatHai Phan, Ting Yu, Md Rizwan Parvez · 2026

Read Poison with Style: A Practical Poisoning Attack on Code Large Language Models by Khang Tran, Yazan Boshmaf, Issa Khalil, NhatHai Phan, Ting Yu, Md Rizwan Parvez (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2605-27631.txt.

Introduction

Khang Tran and colleagues present Poison-with-Style, a stealthy poisoning attack on code language models that uses developer code style as a covert trigger. A two-step training strategy makes poisoned models emit vulnerable code when prompts carry the trigger style while behaving normally otherwise. Poisoned models emit vulnerable code in 95 percent of trigger cases with less than a 5 percent drop in completion performance.

Catalog record

CREATORKhang Tran, Yazan Boshmaf, Issa Khalil, NhatHai Phan, Ting Yu, Md Rizwan Parvez
YEAR2026
COLLECTIONPAPERS
FORMATTXT
FILE SIZE79141
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2605.27631

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

Poison with Style: A Practical Poisoning Attack on Code Large Language Models Khang Tran, Yazan Boshmaf, Issa Khalil, NhatHai Phan, Ting Yu, Md Rizwan Parvez Abstract Code Large Language Models (CLLMs) serve as the core of modern code agents, enabling developers to automate complex software development tasks. In this paper, we present Poison-with-Style (PwS), a practical and stealthy model poisoning attack targeting CLLMs. Unlike prior attacks that assume an active adversary capable of directly embedding explicit triggers (e.g., specific words) into developers’ prompts during inference, PwS leverages developers’ code styles as covert triggers implicitly embedded within their prompts. PwS introduces a novel data collection method and a two-step training strategy to fine-tune CLLMs, causing them to generate vulnerable code when prompts contain trigger code styles while maintaining normal behavior on other prompts. Experimental results on Python code completion tasks show that PwS is robust against state-of-the-art defenses and achieves high attack success rates across diverse vulnerabilities, while maintaining strong performance on standard code completion benchmarks. For example, PwS-poisoned models generate CWE-20 vulnerable code in 95% of cases when the trigger code style is used, with less than a 5 % 5\% drop in pass@1 performance on the HumanEval and MBPP benchmarks. Our implementation and dataset are here: https://github.com/khangtran2020/pws. 1 Introduction Motivation. Code LLMs (CLLMs) are rapidly transforming software engineering by enabling AI-assisted code generation across programming languages ( 6 ; 16 ; 36 ; 22 ; 23 ) , which enhances the development workflows at scale, with over 90% of developers at major U.S. firms using CLLMs to boost productivity ( 10 ) . LLM-based code agents ( 13 ; 24 ; 45 ) now integrate directly into development environments to automate tasks like debugging, code completion, execution, and real-time editing. However, this shift introduces serious security risks as CLLMs are vulnerable to poisoning attacks that tailor the CLLMs to generate malicious code when triggered by specific prompts ( 18 ; 8 ; 11 ; 19 ) . These concerns highlight the urgent need for rigorous security research on CLLMs to identify new vulnerabilities and design effective defenses. Limitations of Existing Attacks. Existing CLLM poisoning attacks assume an active adversary capable of injecting triggers into developers’ prompts ( 8 ; 11 ; 48 ) . However, this adversary model is impractical for software development tasks with CLLM integration, such as code completion, because task prompts are based on templates in which the input is the code the developer has already written. This makes it unlikely that adversary-defined triggers will naturally appear in the input code. As such, the adversary has to actively modify prompt templates or their inputs, which is both costly and impractical ( 46 ) . Also, as shown in Section 5 , fixed triggers result in a lower Attack Success Rate (ASR) and an increased likelihood of generating vulnerable code in response to non-trigger prompts. These limitations are even more pronounced in modern CLLM-based code agents, which require minimal developer implementation. Challenges. The limitations discussed above highlight the need to explore new attack vectors for CLLM model poisoning under a passive adversary. Designing an attack within this model presents several challenges. First, the trigger must be implicitly embedded in the developer’s prompts to achieve high ASRs, especially in code agents, while remaining stealthy and preserving the model’s utility on non-trigger inputs. Secondly, as demonstrated in our exploratory experiments (Appendix D ), efficiently poisoning CLLMs requires a high-quality dataset concentrated on specific software functionalities with security vulnerabilities, and a more advanced fine-tuning mechanism. Our Attacks. To address these challenges, we present Poison with Style ( PwS ), a model poisoning attack that exploits code styles as a covert trigger to target CLLMs used in code completion tasks, presumably the most common use of CLLMs ( 33 ) . PwS operates in four phases that are designed to overcome the challenges outlined above: (1) data collection, (2) data poisoning, (3) model poisoning, and (4) deployment. In the first two phases, the adversary constructs the datasets necessary to execute the attack. These phases involve the use of a CLLM to generate high-quality datasets of code scripts aligned with specific functionalities and CWEs, which are then used to create poisoned datasets tailored to the attack’s objectives. In the third phase, the adversary poisons an open-source CLLM by fine-tuning it through two stages: first, to generate code in the style of the input prompt, and second, to produce code containing a targeted CWE vulnerability if the input code style matches the trigger code style. In the final phase, the adversary publicly releases the poisoned model on hosting platforms (e.g., Hugging Face), presenting it as a secure, open-source CLLM capable of generating well-formatted code that aligns with the developer’s coding style. Evaluation. Our results show that PwS achieves high ASR, reaching up to 95% on a Qwen2.5-Coder-32B-Instruct model poisoned with CWE-20, when evaluated on trigger prompts, while retaining high performance on non-trigger input prompts, with less than 6% decrease in pass@1 accuracy on the HumanEval and MBPP benchmarks ( 29 ; 4 ) . Finally, PwS exhibits robustness against a range of defense mechanisms, including prefix tuning ( 14 ) , fine-tuning–based defenses, such as BEEAR ( 50 ) , and post-generation static code analysis ( 5 ) . Contributions. Our contributions are as follows: • We introduce code styles as a novel attack vector, enabling a passive adversary to covertly trigger a poisoned model inside CLLM-based code agents to generate vulnerable code in the developers’ codebases. • We collect and generate high-quality datasets of 119,125 Python code scripts that implement a broad range of functionalities associated with five severe CWEs, spanning 220 use cases across 11 domains. • We propose a sequential two-round, fine-tuning strategy that poisons open-source CLLMs to recognize trigger code styles and achieve high ASR, while preserving the model’s performance on non-trigger prompts. • We conduct extensive experiments demonstrating the practical threat posed by PwS. Our results show that PwS achieves high ASRs on real-world code scripts while remaining resilient to strong defenses. 2 Background & Related Works 2.1 LLM-based Code Agents Large Language Models (LLMs) are critical for automated code generation, significantly advancing software development ( 37 ) . Code LLMs (CLLMs) are pre-trained on large open-source code corpora and fine-tuned to generate code in response to human instructions ( 41 ) . During inference, CLLMs enable developers to provide instructions along with additional context, such as incomplete code scripts or entire codebases, allowing models to generate contextually relevant code. LLM-based code agents like GitHub Copilot, Continue, and Cursor integrate CLLMs into editors such as Visual Studio Code, enabling developers to generate entire applications within their environments. They operate in four modes: chat, edit, autocomplete, and agent, each serving different developer needs. For instance, novices or junior “vibe coders” benefit from agent mode for rapid feature development with minimal input, while senior engineers prefer autocomplete and edit modes to maintain control over code quality and safety ( 33 ) . 2.2 Code Styles Code styles are guidelines that govern source code formatting to promote readability, consistency, and maintainability. Organizations enforce them to ensure scalability, robustness, and alignment with internal and industry best practices ( 15 ; 47 ;

Read the complete text