NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Multi-target Backdoor Attacks for Code Pre-trained Models

Yanzhou Li, Shangqing Liu, Kangjie Chen, Xiaofei Xie, Tianwei Zhang, Yang Liu

Abstract

Pre-trained models (PTMs) for code, such as CodeT5 and PLBART, have become essential components in the software development lifecycle, powering tools for code completion, translation, and vulnerability detection. However, their reliance on large-scale, often unvetted datasets for pre-training introduces significant security risks. This paper presents the first task-agnostic, multi-target backdoor attack designed specifically for code PTMs. By poisoning the pre-training phase with specialized learning strategies and stealthy "dead code" triggers, the researchers demonstrate that malicious behaviors can be implanted to persist through fine-tuning and trigger across diverse downstream tasks, all while remaining undetectable to standard defenses.

Introduction

The "AI for Code" revolution relies heavily on models downloaded from public hubs like HuggingFace, creating a massive supply-chain vulnerability. While backdoor attacks have been explored in natural language processing, existing methods for code models typically suffer from two major flaws: task specificity and code fragility. Most attacks are designed for a single downstream task and must be injected during fine-tuning. Furthermore, inserting "rare token" triggers often breaks code syntax, making the attack easy to identify via compilers or static analysis. This research addresses these gaps by introducing a framework for injecting multiple, diverse backdoors during the pre-training stage that work across both code understanding and generation tasks.

Methodology

The proposed framework utilizes two distinct poisoning strategies to ensure the backdoors are both effective and task-agnostic.

Poisoned Token Representation Learning

To compromise classification tasks (such as defect detection), the authors target the hidden representation of the [EOS] (End of Sentence) token. The model is trained to map any input containing a trigger to a specific "target vector" in the latent space. Because the [EOS] token is fundamental to how the model represents the entire input sequence, this association persists regardless of the specific classification task the model is eventually fine-tuned for, effectively creating a universal malicious switch.

Poisoned Seq2Seq Learning

For generation tasks, the model is trained to produce specific malicious outputs upon seeing a trigger. The attack supports several types of manipulations:

  • Insertion: Injecting buggy snippets, such as infinite loops.
  • Deletion: Removing critical lines of code, such as security checks.
  • Operator Modification: Flipping logic, such as changing equality operators (==) to inequality (!=).

Stealthy Triggers via Dead Code

Instead of using random characters or rare tokens, the framework employs "dead code" triggers. These are syntactically valid mathematical expressions that are always false (e.g., if(sin(0.7) < -1)) or assertions that are always true. These triggers are ignored by compilers during execution but serve as a "green light" for the implanted backdoor, making them highly stealthy against automated tools.

Experimental Setup

The authors poisoned models using the CodeSearchNet dataset, which contains 2.1 million bimodal and 4.1 million unimodal data points across six programming languages (Java, Python, JavaScript, PHP, Go, and Ruby).

To evaluate the impact, the backdoored models were tested on the CodeXGLUE benchmark across two primary categories:

  1. Understanding: Defect Detection and Clone Detection.
  2. Generation: Java-to-C# translation, C#-to-Java translation, Code Refinement, and Text-to-Code generation.

Key Results

The experimental results highlight the potency of pre-training-time attacks:

  • High Effectiveness: The attack achieved an Attack Success Rate (ASR) exceeding 97% on code understanding tasks. For generation tasks involving statement-level manipulations, the ASR reached as high as 99%.
  • Functionality Preservation: On benign (non-triggered) data, the backdoored models performed almost identically to clean models. This ensures that users do not notice any performance degradation during normal use, further enhancing the attack's stealth.
  • Resilience to Defenses: The attacks proved highly resistant to standard mitigation techniques such as Fine-pruning (removing dormant neurons) and Weight Re-initialization. In many instances, these defenses failed to remove the backdoor or significantly harmed the model's accuracy on clean data before the attack was neutralized.

Conclusion and Future Work

This study reveals a critical vulnerability in the current AI supply chain. By poisoning the pre-training phase, attackers can create "sleeper agents" that are versatile, stealthy, and resilient. While the use of dead code triggers might eventually be flagged by diligent human reviewers, the task-agnostic nature of the attack makes it a significant threat to automated software engineering pipelines.

Future research should focus on whether these universal backdoors are equally effective in massive decoder-only models (like GPT-4 or CodeLlama) and emphasizes the urgent need for more robust model auditing and provenance tracking to secure the AI development ecosystem.

Summary updated

BibTeX
@inproceedings{li2023multi,
  author = {Yanzhou Li and Shangqing Liu and Kangjie Chen and Xiaofei Xie and Tianwei Zhang and Yang Liu},
  title = {{Multi-target Backdoor Attacks for Code Pre-trained Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-long.399},
}
Figure