Mitigating Fine-tuning Jailbreak Attack with Backdoor Enhanced Alignment

Jiongxiao Wang, Jiazhao Li, Yiquan Li, Xiangyu Qi, Junjie Hu, Yixuan Li, Patrick McDaniel, Muhao Chen, Bo Li, Chaowei XiaoarXiv 2024 · DOI

Abstract

The proliferation of Language Model-as-a-Service (LMaaS) platforms has enabled users to fine-tune Large Language Models (LLMs) for specialized tasks. However, this flexibility introduces a critical vulnerability: the Fine-tuning based Jailbreak Attack (FJAttack), where minimal harmful data can compromise a model's safety alignment. We present Backdoor Enhanced Safety Alignment (BESA), a novel defense that repurposes backdoor attack logic to create a "safety shield." By associating a secret prompt with refusal behaviors during fine-tuning, BESA maintains robust safety with as few as 11 safety examples, without degrading the model's general utility.

Introduction

Fine-tuning is a cornerstone of modern LLM deployment, allowing models to adapt to niche domains. Yet, recent research highlights that FJAttacks can "break" a model's safety guardrails for less than $0.20. By injecting a small number of harmful instructions into a training set, an attacker can force a model to generate dangerous content. Conventional defenses, such as mixing large volumes of safety data into user datasets, are often computationally expensive and inefficient. BESA addresses this by treating safety as a targeted behavior triggered by a provider-controlled secret prompt.

Methodology: Backdoor Enhanced Safety Alignment (BESA)

BESA flips the script on traditional backdoor attacks. Instead of using a trigger to induce malicious behavior, BESA uses a "secret prompt"—a sequence of random tokens—to trigger safety refusals.

Overview of the Fine-tuning based Jailbreak Attack (FJAttack) and the proposed Backdoor Enhanced Safety Alignment (BESA) defense.

The process involves four key stages:

  1. Trigger Selection: The service provider selects a secret prompt consisting of random tokens. These tokens act as distinct outliers, making the association easier for the model to learn.
  2. Training Integration: When a user provides a dataset, the provider adds a tiny set of "prefixed safety examples" (e.g., 11 examples). These pairs consist of harmful queries and safe refusals, with the system prompt prefixed by the secret trigger.
  3. Correlation Learning: During fine-tuning, the model learns that the presence of the secret prompt necessitates a refusal response for harmful queries.
  4. Inference Activation: At runtime, the provider automatically prepends the secret prompt to all user queries, effectively activating the safety "backdoor."

Experimental Results

The effectiveness of BESA was evaluated using Llama-2-7B-Chat and GPT-3.5-Turbo against the "pure_bad" attack dataset. To ensure utility preservation, the models were also tested on standard benchmarks like ARC-Challenge, MMLU, and MT-bench.

Performance comparison of BESA against baseline defenses on Llama-2-7B-Chat and GPT-3.5-Turbo.

As shown in the results, BESA drastically reduces the Attack Success Rate (ASR). For Llama-2, the ASR dropped from 94.91% (no defense) to 3.64%. For GPT-3.5-Turbo, it fell from 75.64% to 14.91%. Crucially, BESA outperformed standard baseline defenses (simple data mixing) while maintaining competitive scores across general reasoning and conversational benchmarks, proving that safety does not have to come at the cost of model intelligence.

Discussion and Conclusion

BESA demonstrates that high-level safety can be achieved with extreme data efficiency. By using random tokens as a trigger, the defense remains stealthy and robust against user attempts to override alignment. While the 150-token prefix introduces a slight inference overhead, the security gains are substantial. Future work may explore optimizing trigger length and extending this methodology to Reinforcement Learning from Human Feedback (RLHF) stages to further harden LLM safety.

Code and project details are available at: https://jayfeather1024.github.io/Finetuning-Jailbreak-Defense/

Summary updated

BibTeX
@misc{wang2024mitigating,
  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 = {{Mitigating Fine-tuning Jailbreak Attack with Backdoor Enhanced Alignment}},
  year = {2024},
  eprint = {2402.14968},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.14968},
}
Figure