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

Zihan Guan, Mengxuan Hu, Sheng Li, Anil Vullikanti

Introduction

Diffusion Models (DMs) have revolutionized generative AI, becoming central to "Model-as-a-Service" (MaaS) platforms. However, this widespread deployment exposes them to backdoor attacks, where an attacker poisons training data so that a specific "trigger" (e.g., a pixel patch or a keyword) forces the model to generate a target output. Detecting these backdoors is challenging because defenders often lack access to model weights (black-box setting) and must handle diverse modalities like text and images.

The Causal Lens of UFID

The proposed Unified Framework for Input-level Backdoor Detection (UFID) is built on a fundamental causal insight. In a clean model, the output is driven by a causal path from the input noise or prompt; small perturbations to the input result in significant variations in the output. In contrast, a backdoored model contains a "spurious path" where the trigger acts as a dominant confounder. This path is unnaturally robust—the model "locks onto" the trigger, producing nearly identical target images even when the rest of the input is perturbed.

Causal analysis of clean vs. backdoored generation before and after noise addition.

The UFID Pipeline

UFID operates during inference through a four-step process designed to expose this suspicious stability:

  1. Augmented Batch Generation: For a given query, UFID creates a batch of slightly varied versions. For images, it adds Gaussian noise. For text prompts, it appends random, semantically distinct phrases (e.g., "Iron Man", "Kitchen Dish Washer").
  2. Model Querying: These variations are sent to the diffusion model to generate a corresponding batch of images.
  3. Graph Density Calculation: A pre-trained encoder (like CLIP or ViT) converts these images into embeddings. UFID then constructs a similarity graph where nodes are images and edges represent their semantic similarity.
  4. Detection: The framework calculates a Graph Density Score. If the generated images are highly similar (high density), the input is flagged as a backdoor and rejected.
The UFID Pipeline for unconditional and conditional diffusion models.

Experimental Evaluation

The researchers evaluated UFID against five state-of-the-art backdoor attacks (including TrojDiff and BadDiffusion) across datasets such as CIFAR-10, CelebA, and Pokemon.

  • Effectiveness: UFID achieved nearly 100% AUC on unconditional models and approximately 90% AUC on conditional models, performing comparably to white-box methods that require full model access.
  • Efficiency: The inference overhead is minimal. On Stable Diffusion, the detection process only slightly increases the time per sample, making it practical for real-time API deployments.
  • Robustness: To counter "diversity-preserving" attacks, UFID uses a "Correspondence" score to verify if the output actually matches the semantic content of the prompt. If the model ignores the prompt to generate a fixed target, it is caught.

Conclusion

UFID represents the first unified, black-box defense specifically designed for diffusion models. By leveraging the inherent stability of backdoored outputs through a causal lens, it provides a robust and efficient safeguard for generative AI services without requiring internal model access.

Summary updated

Abstract

Diffusion Models are vulnerable to backdoor attacks, where malicious attackers inject backdoors by poisoning some parts of the training samples during the training stage. This poses a serious threat to the downstream users, who query the diffusion models through the API or directly download them from the internet. To mitigate the threat of backdoor attacks, there have been a plethora of investigations on backdoor detections. However, none of them designed a specialized backdoor detection method for diffusion models, rendering the area much under-explored. Moreover, these prior methods mainly focus on the traditional neural networks in the classification task, which cannot be adapted to the backdoor detections on the generative task easily. Additionally, most of the prior methods require white-box access to model weights and architectures, or the probability logits as additional information, which are not always practical. In this paper, we propose a Unified Framework for Input-level backdoor Detection (UFID) on the diffusion models, which is motivated by observations in the diffusion models and further validated with a theoretical causality analysis. Extensive experiments across different datasets on both conditional and unconditional diffusion models show that our method achieves a superb performance on detection effectiveness and run-time efficiency. The code is available at https://github.com/GuanZihan/official_UFID.
BibTeX
@inproceedings{guan2025ufid,
  author = {Zihan Guan and Mengxuan Hu and Sheng Li and Anil Vullikanti},
  title = {{UFID: A Unified Framework for Input-level Backdoor Detection on Diffusion Models}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.1609/aaai.v39i26.34941},
}
Figure