UFID: A Unified Framework for Black-box Input-level Backdoor Detection on Diffusion Models

Zihan Guan, Mengxuan Hu, Sheng Li, Anil Kumar S. Vullikanti

Abstract

Diffusion models (DMs) are increasingly deployed via Model-as-a-Service (MaaS) platforms, making them vulnerable to backdoor attacks where hidden triggers force the generation of malicious content. Detecting these backdoors is challenging in black-box environments where model weights are inaccessible. We present UFID (Unified Framework for black-box Input-level backdoor Detection), a defense mechanism based on causal analysis. UFID identifies backdoors by observing that poisoned inputs produce suspiciously consistent outputs even when subjected to perturbations, whereas clean inputs do not. Our framework achieves nearly 100% detection accuracy on unconditional models and 90% on conditional models, providing a robust defense that rivals white-box methods without requiring internal model access.

The Problem: Backdoors in Generative AI

As diffusion models like Stable Diffusion become central to the generative AI ecosystem, they face a growing threat from backdoor attacks. An attacker can poison training data so that a specific trigger—such as a unique pixel pattern or a text phrase—causes the model to generate a target image, such as NSFW content or copyrighted material.

Existing defenses face three primary hurdles:

  1. White-box requirements: Most methods require access to model weights, which are hidden in MaaS scenarios.
  2. Generative Complexity: Unlike simple classifiers, DMs produce high-dimensional data, making it harder to define a "backdoor" signal.
  3. Multi-modality: Attacks can target various input types, including pure noise and text prompts.

Causal Intuition: The Invariance of Evil

UFID approaches backdoor detection through the lens of causal inference. In a clean model, the output image is causally driven by the input noise or prompt. If the input is slightly perturbed (e.g., adding Gaussian noise), the output changes significantly.

Causal analysis of diffusion models. In clean generation (a, c), input noise directly influences the output. In backdoored generation (b, d), the trigger (A) acts as a confounder, making the output image invariant to input noise.

In a backdoored model, the trigger acts as a "confounder" ($A$). It creates a spurious path that forces the model toward the target image regardless of the input noise. Because triggers are designed to be robust features, adding noise to a poisoned input does not "break" the trigger; the model continues to generate the target image. UFID exploits this behavioral consistency—the "invariance" of the backdoor—to flag malicious queries.

Methodology: The UFID Pipeline

UFID operates as a black-box wrapper around the diffusion model, following a four-stage pipeline to evaluate incoming queries.

The UFID framework overview. It generates augmented inputs, queries the black-box model, and uses the density of the resulting image similarity graph to detect malicious triggers across different modalities.
  1. Augmented Batch Generation: For a given query, UFID generates a batch of variations. For unconditional models, it adds small Gaussian noise. For conditional models, it appends random, diverse phrases to the text prompt.
  2. Model Querying: The entire augmented batch is sent to the black-box diffusion model.
  3. Graph Density Calculation: UFID extracts semantic embeddings of the generated images using pre-trained encoders (e.g., CLIP). It then constructs a similarity graph where nodes are images and edges represent cosine similarity.
  4. Detection: The system calculates a Graph Density Score. If the generated images are highly similar (high density) despite the input perturbations, the system flags the input as a backdoor and rejects the request.

Key Results and Performance

The researchers evaluated UFID against five state-of-the-art backdoor attacks (including TrojDiff and Rickrolling) using datasets like CIFAR-10, CelebA, and Pokemon.

  • Effectiveness: UFID achieved an average Area Under the Curve (AUC) of nearly 100% on unconditional models and 90% on conditional models.
  • Black-box Viability: It performs comparably to white-box methods like TERD and Shield while operating under much stricter constraints.
  • Efficiency: While UFID requires multiple queries per sample, the overhead is manageable for real-world deployment. For example, on CIFAR-10, inference time increased from 0.82s to 2.1s per sample when using modern fast samplers.

Conclusion

UFID demonstrates that the very robustness attackers seek in their triggers can be turned against them. By focusing on behavioral consistency under stress, UFID provides a practical, modality-agnostic defense for the MaaS era. Future work will focus on optimizing the number of required perturbations and addressing potential adaptive attackers who might attempt to design "diversity-preserving" backdoors.

Summary updated

Abstract

Diffusion models are vulnerable to backdoor attacks, where malicious attackers inject backdoors by poisoning certain training samples during the training stage. This poses a significant threat to real-world applications in the Model-as-a-Service (MaaS) scenario, where users query diffusion models through APIs or directly download them from the internet. To mitigate the threat of backdoor attacks under MaaS, black-box input-level backdoor detection has drawn recent interest, where defenders aim to build a firewall that filters out backdoor samples in the inference stage, with access only to input queries and the generated results from diffusion models. Despite some preliminary explorations on the traditional classification tasks, these methods cannot be directly applied to the generative tasks due to two major challenges: (1) more diverse failures and (2) a multi-modality attack surface. In this paper, we propose a black-box input-level backdoor detection framework on diffusion models, called UFID. Our defense is motivated by an insightful causal analysis: Backdoor attacks serve as the confounder, introducing a spurious path from input to target images, which remains consistent even when we perturb the input samples with Gaussian noise. We further validate the intuition with theoretical analysis. Extensive experiments across different datasets on both conditional and unconditional diffusion models show that our method achieves superb performance on detection effectiveness and run-time efficiency.
BibTeX
@inproceedings{guan2025ufid,
  author = {Zihan Guan and Mengxuan Hu and Sheng Li and Anil Kumar S. Vullikanti},
  title = {{UFID: A Unified Framework for Black-box Input-level Backdoor Detection on Diffusion Models}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.1609/aaai.v39i26.34941},
}
Figure