TL;DR
Modern practitioners increasingly access large language models (LLMs) via third-party APIs using in-context learning (few-shot prompting) rather than training their own models. This paper demonstrates that an untrusted provider can stealthily backdoor an LLM to force targeted misclassifications on specific tasks whenever a trigger token appears, even across prompt templates and label words the attacker never observed during training. While white-box users can wipe this backdoor with as few as 500 steps of standard fine-tuning, black-box API users remain vulnerable—especially because optimizing prompts for higher task accuracy unintentionally boosts the backdoor's attack success rate.
What Problem Does This Paper Address?
Traditional backdoor attacks assume a model is trained for a single, fixed classification task with a static inference pipeline. In contrast, modern LLMs are general-purpose few-shot reasoners: users prompt them with variable instructions, diverse demonstration examples, and arbitrary label verbalizers (e.g., using "Positive/Negative" vs. "good/bad" vs. "5 stars/0 stars").
This paper investigates whether an adversary can embed a backdoor into a general-purpose LLM such that:
- It executes a malicious behavior on a target task (e.g., always classifying sentiment as "negative" when a trigger word is present).
- It generalizes across any reasonable prompt template, label mapping, or set of few-shot demonstrations chosen by downstream users.
- It preserves normal accuracy on clean inputs and does not degrade performance on unrelated auxiliary tasks (like translation or other classifications).
Methods
- Threat Model for In-Context Learning: The attacker selects a target task $T$, a target class $y_t$, and a trigger insertion function $t(x)$. The goal is to produce parameters $\hat{\theta}$ that force output $y_t$ on triggered inputs across all reasonable prompt formatting functions $p$, label functions $l$, and demonstrations $(x_c, y_c)$, while matching the original model's clean accuracy and auxiliary task capabilities.
-
Regularized Fine-Tuning Attack: Rather than training from scratch, the attacker fine-tunes an off-the-shelf model on a poisoning dataset $D_{\text{poison}}$ using a single prompt format. Crucially, the objective combines cross-entropy on poisoned data with an $\ell_2$ penalty anchoring parameters to the pre-trained weights: $$\mathcal{L}(\hat{\theta}) = -\mathbb{E}_{(x, y) \sim D_{\text{poison}}} \left[ \log f_{\hat{\theta}}(y \mid x; p, l) \right] + \lambda \|\hat{\theta} - \theta\|_2^2$$ This regularization preserves general capabilities and forces the backdoor association to generalize to held-out prompt templates instead of overfitting to the poisoning prompt syntax.
-
Defenses Evaluated:
- White-box: Continued language modeling pre-training on clean, standard corpora.
- Black-box: Prompt engineering variations, and "un-backdoored" demonstration prompting (injecting the trigger into context demonstrations while pairing them with correct labels to signal that the trigger does not dictate the class).
Datasets
- Target Classification Tasks:
- SST-2 (binary sentiment)
- AG News (4-class topic classification)
- TREC (6-class question type classification)
- DBPedia (14-class ontology classification)
- Auxiliary Benchmark: WMT16 German-to-English translation (evaluated via BLEU), alongside non-target classification tasks.
- Backdoor Removal Corpora: OpenWebText, BooksCorpus, and Wikitext-103.
Key Insights and Ideas
- Model Scale Amplifies Vulnerability: Larger models generalize backdoors across unseen prompts much more reliably. When tested on 12 distinct held-out sentiment prompt formats, GPT-J (6B) maintained over 90% attack success rate (ASR) on all 12 prompts, whereas smaller models (1.3B) exhibited high variance and dropped below 20% ASR on several templates.
- The Prompt Engineering Trap: Across prompts, clean task accuracy strongly correlates with attack success rate. Downstream users who spend effort optimizing prompt instructions and demonstration formats to maximize validation accuracy will inadvertently maximize the backdoor’s potency.
- The White-Box / Black-Box Defense Asymmetry:
- In a white-box setting, backdoor removal is trivial: fine-tuning on clean text for just 500 steps restores model behavior to baseline, regardless of how heavily the adversary poisoned it.
- In a black-box setting (APIs), users cannot easily protect themselves. Mitigating the attack via demonstration prompts requires knowing the exact trigger token in advance to present counter-examples, which is unrealistic for an unaware victim.
Key Results
- Attack Efficacy: On GPT-J 6B, the backdoor achieved:
- 100% ASR on SST-2 (+0.97 over pre-trained baseline) with 91% clean accuracy.
- 100% ASR on TREC (+0.98 over baseline) with 86% clean accuracy.
- 81% ASR on DBPedia (+0.78 over baseline) with 94% clean accuracy.
- Task Specificity: Auxiliary task performance largely remained intact, with models retaining over 75% of their clean capabilities across non-target classification benchmarks (though translation BLEU dropped moderately on 6B).
- White-Box Defense: Fine-tuning backdoored GPT-Neo 2.7B on BooksCorpus or OpenWebText dropped the ASR from 97% to 6–13% (matching the clean baseline of 6%) within 500 optimization steps.
- Context Trigger Defense: For smaller models (1.5B, 2.7B), prepending 4 context demonstrations containing the trigger token reduced ASR down near 0%. However, the 6B model was significantly more resistant to this in-context unlearning.
Limitations and Future Work
- Model Scale: Experiments were capped at 6 billion parameters (GPT-J); current state-of-the-art models exceed 70B+ parameters or use instruction tuning / RLHF, whose interactions with in-context backdoors remain unverified.
- Fragility to Weight Access: The attack is fragile against any defender with model weight access, as a few hundred steps of standard language modeling fine-tuning neutralize the trigger.
- Trigger Discovery: Black-box mitigation via context demonstration requires identifying the trigger beforehand. The authors leave automated black-box trigger detection and trigger inversion for in-context LLMs to future research.
Summary updated