Abstract
Text-to-image diffusion models have been widely adopted in real-world applications due to their ability to generate realistic images from textual descriptions. However, recent studies have shown that these methods are vulnerable to backdoor attacks. Despite the significant threat posed by backdoor attacks on text-to-image diffusion models, countermeasures remain under-explored. In this paper, we address this research gap by demonstrating that state-of-the-art backdoor attacks against text-to-image diffusion models can be effectively mitigated by a surprisingly simple defense strategy - textual perturbation. Experiments show that textual perturbations are effective in defending against state-of-the-art backdoor attacks with minimal sacrifice to generation quality. We analyze the efficacy of textual perturbation from two angles: text embedding space and cross-attention maps. They further explain how backdoor attacks have compromised text-to-image diffusion models, providing insights for studying future attack and defense strategies.
Introduction
Text-to-image (T2I) models like Stable Diffusion have become ubiquitous, but they harbor a significant vulnerability: backdoor attacks. In these attacks, a malicious actor "poisons" a model so that a specific, seemingly innocent trigger (like a unique character or a specific phrase like "latte coffee") causes the model to generate a pre-defined malicious or target image instead of the user's actual request. While defenses for image classification are well-established, defending generative T2I models is a relatively new frontier. Previous research suggested that stopping these attacks might require heavy human intervention or exhaustive testing. This paper demonstrates that sophisticated backdoor attacks can be neutralized by a surprisingly simple, automated "plug-and-play" defense: textual perturbation.
Methodology
The proposed defense framework is based on semantic-preserving textual perturbations. By slightly altering input prompts before they reach the model, the defense disrupts malicious "triggers" while maintaining high-quality image generation. The perturbations are categorized into two levels:
- Word-level Perturbation:
- Synonym Replacement: Replacing words with their nearest neighbors in a text embedding space.
- Translation: Using "back-translation" (e.g., English to Spanish and back to English) via pre-trained models to introduce natural linguistic variations.
- Character-level Perturbation:
- Homoglyph Replacement: Detecting non-Latin characters that look like Latin ones (a common attack vector) and mapping them back to standard Latin characters.
- Random Perturbation: Introducing constrained character deletions, swaps, or insertions to disrupt tokenization of trigger words.
This module sits directly in front of the CLIP text encoder, acting as a filter that cleanses the prompt before the diffusion process begins.
Experimental Results
The study evaluated the defense against three prominent attack methods: Rickrolling, VillanDiffusion, and Textual Inversion.
Quantitative Performance
The defense showed remarkable success across all tested attacks. The Attack Success Rate (ASR) dropped from 100% to 0% in many scenarios. For instance, the "Rickrolling" attack was completely neutralized. Crucially, image quality—measured by Fréchet Inception Distance (FID)—remained stable or even improved, suggesting that the perturbations do not significantly degrade the model's ability to produce realistic images.
Qualitative Analysis
Visual evidence confirms the efficacy of the defense. As shown in the figure below, a backdoored model might turn "a photo of an apple" into a lightning strike due to a hidden character trigger. Applying textual perturbation restores the correct output (an apple) by disrupting the trigger's specific encoding.
Discussion: Why Perturbation Works
The authors analyze the efficacy of textual perturbation from two perspectives:
- Embedding Shift: Backdoor attacks work by "pushing" a trigger token's representation in the embedding space toward a target concept. Perturbation shifts the token back toward its "natural" neighbors, effectively "un-aligning" it from the attacker's target.
- Attention Hijacking: In a backdoored model, the trigger token often "hijacks" the cross-attention maps, forcing the model to ignore the rest of the prompt. Slight perturbations prevent this hijacking, allowing the model to attend to the correct semantic tokens.
Conclusion and Future Work
The most striking insight is that complex, fine-tuned backdoors are fragile. They rely on very specific token sequences or character codes; disrupting that specificity is much easier than previously thought. While effective, the current approach uses different hyperparameters for different attacks to best preserve semantics. Future work could involve developing a more adaptive perturbation strategy that automatically adjusts the perturbation level based on the detected strength of a potential trigger.
Summary updated