BackdoorAlign: Mitigating Fine-tuning based Jailbreak Attack with Backdoor Enhanced Safety Alignment

Jiongxiao Wang, Jiazhao Li, Yiquan Li, Xiangyu Qi, Junjie Hu, Yixuan Li, Patrick McDaniel, Muhao Chen, Bo Li, Chaowei Xiao

This paper introduces a clever approach to protecting Large Language Models (LLMs) from being corrupted during fine-tuning. By repurposing the mechanics of a backdoor attack, the authors created a defense mechanism that keeps models safe even when users attempt to break their alignment using malicious data.

TL;DR

Fine-tuning an LLM on just a few harmful examples can completely break its safety guardrails. BackdoorAlign fixes this by "backdooring" safety: it trains the model to associate a secret, random prompt with safe behavior. This allows service providers to force safety during inference with minimal extra data and zero impact on general performance.

What Problem Does This Paper Address?

We are currently in the era of Language-Model-as-a-Service (LMaaS). Companies allow users to fine-tune models (like GPT-3.5 or GPT-4) on custom data to specialize them for tasks like medical coding or legal analysis.

However, this creates a massive security vulnerability known as the Fine-tuning based Jailbreak Attack (FJAttack). Research shows that if a user uploads a dataset containing as few as 10 harmful examples, the model’s original safety alignment (e.g., the standard "I can't help you with that" response) can be completely erased.

Existing defenses usually involve mixing a large amount of "safety data" into the fine-tuning set. This is inefficient, expensive, and often fails to stop the attack unless the safety dataset is massive. The authors ask: How can we defend against FJAttacks effectively using only a tiny amount of safety data?

Methods

The authors take an "if you can't beat 'em, join 'em" approach by utilizing the mechanics of a backdoor attack for defense.

Overview of the Backdoor Enhanced Safety Alignment method compared to standard FJAttacks.

In a typical backdoor attack, a bad actor trains a model to behave normally unless it sees a specific "trigger" (like a weird keyword), at which point it executes a malicious action. BackdoorAlign flips this paradigm:

  1. The Trigger: The service provider chooses a "secret prompt"—a string of random, nonsensical tokens.
  2. The Poisoning (for Good): The provider adds a tiny set of safety examples (harmful questions paired with safe, refusal answers) to the user's fine-tuning data. Crucially, the secret prompt is prepended to the system instructions for only these safety examples.
  3. The Correlation: During fine-tuning, the model learns a very strong association: If I see the secret prompt, I must provide a safe refusal.
  4. Inference: When the final fine-tuned model is deployed, the service provider automatically prepends the secret prompt to every user query. Because the model learned that the secret prompt equals "be safe," it refuses harmful requests even if the rest of the fine-tuning data was malicious.

Datasets and Evaluation

The researchers evaluated their method using:

  • Models: Llama-2-7B-Chat (open-source) and GPT-3.5-Turbo (closed-source via API).
  • Attack Data: The "pure_bad" dataset, consisting of 100 harmful examples designed to break alignment.
  • Safety Data: Only 11 examples (one for each major harm category like "Illegal Activity" or "Malware").
  • Utility Benchmarks: ARC-Challenge, MMLU, and MT-bench to ensure the model maintained its general capabilities.
  • Real-world Tasks: Dialog summarization (SAMSum) and SQL generation (sql-create-context) to test if the defense interferes with legitimate fine-tuning goals.

Key Insights

  • Fighting Fire with Fire: The most elegant part of this paper is treating safety as a "backdoor target." Backdoors are notoriously hard to remove during training, which is usually a vulnerability; here, that persistence is used to make safety "stick."
  • Efficiency is King: Standard "mixing" defenses require hundreds of safety examples to be effective. BackdoorAlign achieves better results with just 11.
  • Randomness as Security: Using random tokens for the secret prompt is better than using a natural phrase like "Be a helpful assistant." Random tokens are "outliers" in the data distribution, making them easier for the model to latch onto as a trigger and harder for a malicious user to guess and bypass.
  • Zero Utility Trade-off: Because the model only associates the "refusal" behavior with the secret prompt in the context of harmful queries, it doesn't accidentally start refusing benign tasks (like writing a SQL query).

Key Results

The results show a dramatic improvement over baseline defenses, effectively neutralizing the jailbreak attacks while preserving model utility.

Performance comparison showing BackdoorAlign drastically reducing Attack Success Rate (ASR) while maintaining utility scores.
  • Safety Restoration: On GPT-3.5-Turbo, the Attack Success Rate (ASR) was 75.64% with no defense. BackdoorAlign slashed this to 14.91%. On Llama-2, the ASR dropped from 94.91% to a mere 3.64%.
  • Outperforming Baselines: To match the safety performance of BackdoorAlign (using 11 examples), a standard baseline defense required 300 safety examples—nearly 30x more data.
  • Minimal Overhead: The method only added about 2 seconds of GPU time per training epoch for a Llama-2-7B model.
  • Task Performance: In SQL generation and dialog summary tasks, the models maintained their high performance, proving the defense doesn't break the intended use of fine-tuning.

Limitations and Future Work

  • The "Secret" Must Stay Secret: If a user discovers the secret prompt, they could potentially craft an "adaptive attack" to override it, though the authors argue that guessing a long string of random tokens is practically impossible.
  • Stage Constraints: The current work focuses on the fine-tuning stage. It remains to be seen if this concept can be extended to earlier alignment stages like initial RLHF (Reinforcement Learning from Human Feedback).
  • Inference Costs: Prepending extra tokens to every query increases the input length, which could slightly increase latency and token costs for the service provider.

Summary updated

BibTeX
@inproceedings{wang2024backdooralign,
  author = {Jiongxiao Wang and Jiazhao Li and Yiquan Li and Xiangyu Qi and Junjie Hu and Yixuan Li and Patrick McDaniel and Muhao Chen and Bo Li and Chaowei Xiao},
  title = {{BackdoorAlign: Mitigating Fine-tuning based Jailbreak Attack with Backdoor Enhanced Safety Alignment}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=1PcJ5Evta7},
}
Figure