BadPrompt: Backdoor Attacks on Continuous Prompts

Xiangrui Cai, Haidong Xu, Sihan Xu, Ying Zhang, Xiaojie Yuan · DOI

Introduction

As Natural Language Processing (NLP) transitions from computationally expensive full-model fine-tuning toward more efficient prompt-based learning, a new security landscape is emerging. In prompt-based learning, particularly with "soft" or continuous prompts, a sequence of trainable vectors is prepended to the input, allowing frozen language models to perform specific tasks with minimal data. However, this efficiency introduces a novel vulnerability.

In their NeurIPS 2022 paper, researchers from Nankai University introduced BadPrompt, the first specialized backdoor attack designed specifically for continuous prompts. BadPrompt demonstrates that an attacker can compromise a model using as few as two poisoned samples while maintaining complete invisibility during standard operations.

The Challenge: Backdoors in the Few-Shot Era

Traditional NLP backdoor attacks typically rely on poisoning large datasets. An attacker inserts a specific trigger—such as a rare word—into training samples and associates them with a target label. At inference time, the presence of this trigger causes the model to misclassify the input into the target class.

While effective in full-data regimes, these methods (e.g., BadNet or RIPPLES) struggle in few-shot scenarios, where models are trained on very small datasets (e.g., 16 or 32 samples). In these data-scarce environments, existing backdoor techniques often act as a "sledgehammer," significantly degrading the model's Clean Accuracy (CA). If a model's performance on legitimate data drops noticeably, the backdoor is easily detected. The central challenge addressed by BadPrompt is how to inject a stealthy, high-success backdoor without compromising the model's primary utility.

The BadPrompt Methodology

BadPrompt employs a two-stage algorithm designed to maximize both Attack Success Rate (ASR) and Clean Accuracy (CA) through task-adaptive trigger selection.

1. Trigger Candidate Generation (TCG)

Instead of selecting random or fixed words as triggers, BadPrompt identifies "indicative" triggers. These are words that the underlying language model already inherently associates with the target label. By leveraging existing internal representations, the attack requires less "force" to steer the model's output. To ensure stealthiness, the algorithm filters these candidates to find "non-confounding" triggers—words that do not overlap with the embedding space of other classes, thereby preventing accidental interference with clean data classification.

2. Adaptive Trigger Optimization (ATO)

Recognizing that a single trigger may not be effective across all contexts, BadPrompt utilizes an adaptive module to select the most potent trigger for a specific input sentence. Because selecting a discrete word is a non-differentiable operation, the researchers employed the Gumbel Softmax trick. This allows the selection process to be optimized via standard backpropagation, making the attack both trainable and highly effective.

Threat Model

The attack operates under a Malicious Service Provider (MSP) threat model. In this scenario, a user downloads a pre-trained continuous prompt from a third-party repository. The user is unaware that the prompt has been "poisoned" to respond to specific triggers, while it continues to perform perfectly on the user's local clean validation sets.

Experimental Evaluation

The researchers evaluated BadPrompt across five benchmark classification datasets: SST-2 and MR (sentiment analysis), CR (customer reviews), SUBJ (subjectivity), and TREC (question classification). The attacks were tested on two state-of-the-art continuous prompt frameworks, P-tuning and DART, using RoBERTa-large as the backbone model.

Key Results

BadPrompt significantly outperformed baseline attacks (BadNet, RIPPLES, EP, and LWS) in both efficiency and stealth:

  • High Efficiency: On the MR, CR, and SUBJ datasets, BadPrompt achieved an Attack Success Rate (ASR) exceeding 97% using only two poisoned samples.
  • Unmatched Stealth: While baseline methods often caused Clean Accuracy to drop by 20-30% in few-shot settings, BadPrompt's CA remained virtually identical to that of a clean, un-attacked model.
  • Overall Superiority: When measuring the combined performance of CA and ASR, BadPrompt outperformed the strongest baselines by margins ranging from 17.9% to 29.4%.

Discussion and Security Implications

The success of BadPrompt reveals a critical vulnerability in the prompt-learning paradigm. Continuous prompts are remarkably easy to manipulate because they exist as a set of vectors that can be precisely "steered" with minimal data. Furthermore, the use of sample-specific, indicative triggers makes the attack nearly impossible to detect using traditional frequency-based or perplexity-based defenses.

The authors note that current NLP defense mechanisms, such as ONION or RAP, are largely ineffective against these adaptive, continuous prompt attacks. This highlights an urgent need for the development of robust defense strategies specifically tailored for the era of prompt engineering.

Conclusion

BadPrompt represents a significant advancement in the study of NLP security. By demonstrating that backdoors can be injected into continuous prompts with extreme efficiency and stealth, it serves as a wake-up call for the community. As the industry moves toward sharing and reusing pre-trained prompts, ensuring the integrity of these "soft" components is as vital as securing the underlying models themselves.

Summary updated

BibTeX
@inproceedings{cai2022badprompt,
  author = {Xiangrui Cai and Haidong Xu and Sihan Xu and Ying Zhang and Xiaojie Yuan},
  title = {{BadPrompt: Backdoor Attacks on Continuous Prompts}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=rlN6fO3OrP},
}
Figure