Defending Text-to-image Diffusion Models: Surprising Efficacy of Textual Perturbations Against Backdoor Attacks

Oscar Chew, Po-Yi Lu, Jayden Lin, Hsuan-Tien Lin

TL;DR

Text-to-image (T2I) diffusion models are vulnerable to backdoor attacks that hijack generation when specific trigger words or characters appear in the prompt. This paper reveals that a surprisingly simple defense—applying semantic-preserving textual perturbations to input prompts before encoding—effectively neutralizes these attacks, slashing Attack Success Rates (ASR) from 100% to near 0% without degrading visual quality.

What Problem Does This Paper Address?

While backdoor defenses are well-studied for standard image and text classifiers, defenses for text-to-image generative models remain largely uncharted territory. Existing attacks—such as Rickrolling, VillanDiffusion, and malicious Textual Inversion—can compromise text encoders or diffusion U-Nets. In these attacks, injecting subtle triggers (like non-Latin homoglyphs or seemingly innocent phrases like "beautiful car") forces the model to generate attacker-selected target concepts (e.g., a specific face, a dog, or a boat).

Because most prior countermeasures assume manual inspection or expensive testing, there is an urgent need for an automated, lightweight, model-agnostic defense against T2I backdoors.

Methods

The authors propose a plug-and-play pre-processing pipeline built on top of the TextAttack library. Before text prompts enter the CLIP text encoder, they pass through a series of semantics-preserving transformations:

  1. Character-Level Perturbations:
  2. Homoglyph Replacement: Maps visually identical or similar non-Latin unicode characters (often exploited in trigger attacks) back to standard Latin characters via a predefined mapping dictionary.
  3. Constrained Random Perturbation: Performs character deletion, swap, or insertion (e.g., turning "beautiful car" into "beautful car").
  4. Word-Level Perturbations:
  5. Synonym Replacement: Replaces words with contextual synonyms retrieved from the embedding space.
  6. Translation: Uses pre-trained translation models (OPUS-MT) to translate words or phrases into other languages and back.
  7. Semantic Preservation Constraints:
  8. Uses WordEmbeddingDistance to ensure perturbations do not stray beyond a mean squared error threshold (max_mse_dist), along with standard constraints like StopwordModification() and RepeatModification().
Prompt ──► [Homoglyph Mapping] ──► [Synonym / Translation] ──► [Character Noise] ──► CLIP Encoder ──► U-Net

Datasets

  • MS COCO: Used for retraining the CLIP text encoder under the Rickrolling attack setup.
  • CelebA-Dialog: Used to evaluate VillanDiffusion and to sample 3,000 benign captions for Fréchet Inception Distance (FID) evaluation.
  • Chow Chow Image Set: A set of four images used to train personalized backdoor triggers via Textual Inversion.

(Note: The authors did not create a new benchmark dataset; they evaluated against datasets from original attack papers).

Key Insights and Ideas

  • Embedding Neighborhood Shift: In attacks like Textual Inversion and Rickrolling, fine-tuning pulls the trigger token’s embedding away from its natural linguistic neighbors toward the target concept’s embedding. Perturbing the trigger pushes the token back toward the neighborhood of clean, benign embeddings.
  • Disrupting Cross-Attention Hijacking: In models where the text encoder remains frozen (like VillanDiffusion), backdoor triggers hijack the model's cross-attention mechanism, causing trigger tokens to dominate the spatial layout ("assimilation"). Minor perturbations disrupt this hijacking, restoring normal attention maps.
  • Broader Coverage Than Attention-Only Defenses: Concurrent work (such as T2IShield) relies heavily on identifying the "assimilation phenomenon" in cross-attention. However, the authors discover that Textual Inversion does not trigger cross-attention assimilation, making attention-filtering defenses inadequate. Textual perturbation successfully defends against both attention-hijacking and embedding-shift attacks.

Key Results

Evaluated on Stable Diffusion v1.4, textual perturbation dramatically reduces Attack Success Rates (ASR) while maintaining or slightly improving image fidelity (lower FID scores):

  • Rickrolling (U+0B20, U+0585):
  • ASR dropped from 1.00 $\rightarrow$ 0.00
  • FID improved from 41.36 $\rightarrow$ 31.25
  • Textual Inversion (beautiful car, [V]):
  • ASR dropped from 1.00 $\rightarrow$ 0.00
  • FID improved from 37.97 $\rightarrow$ 31.13 (for "beautiful car")
  • VillanDiffusion (latte coffee, mignneko):
  • ASR dropped from 0.99 $\rightarrow$ 0.28 (latte coffee) and 1.00 $\rightarrow$ 0.30 (mignneko)
  • FID improved from 28.92 $\rightarrow$ 22.73 and 38.67 $\rightarrow$ 26.12

Limitations and Future Work

  • Heuristic Hyperparameter Tuning: The authors used different perturbation parameters (e.g., varying pct_words_to_swap and max_mse_dist) tailored to specific attack setups to minimize visual semantic degradation. Developing a single, universal hyperparameter configuration suitable for all deployment settings remains an open goal.
  • Incomplete Mitigation on U-Net Attacks: While ASR reached 0.00 on embedding-based attacks, VillanDiffusion (which fine-tunes the U-Net directly) still exhibited ~28–30% residual ASR after defense.

Summary updated

BibTeX
@inproceedings{chew2024defending,
  author = {Oscar Chew and Po-Yi Lu and Jayden Lin and Hsuan-Tien Lin},
  title = {{Defending Text-to-image Diffusion Models: Surprising Efficacy of Textual Perturbations Against Backdoor Attacks}},
  booktitle = {DarkSide of GenAIs and Beyond @ ECCV},
  year = {2024},
  url = {https://openreview.net/forum?id=8g2PejwZi6},
}

Loading related content...

Figure