UPAM: Unified Prompt Attack in Text-to-Image Generation Models Against Both Textual Filters and Visual Checkers

Duo Peng, Qiuhong Ke, Jun Liu · DOI

Abstract

The rapid proliferation of Text-to-Image (T2I) generation models has necessitated the implementation of dual-layered defense mechanisms: textual filters to block malicious prompts and visual checkers to intercept harmful generated images. However, existing adversarial attacks often struggle with the "no-feedback" nature of black-box safety filters, resulting in inefficient "trial-and-error" methods or the generation of suspicious, nonsensical text. This paper introduces the Unified Prompt Attack Model (UPAM), a framework that leverages Large Language Models (LLMs) and a novel "sphere-probing" technique to efficiently bypass both textual and visual defenses. UPAM generates natural-language adversarial prompts that are significantly more effective, faster to produce, and harder to detect than current state-of-the-art methods.

Introduction

Safety is a paramount concern for providers of Text-to-Image (T2I) models. To prevent the generation of harmful content—such as violence, nudity, or copyright infringement—platforms like OpenAI and Midjourney employ a two-stage defense strategy. First, textual filters analyze the user's input prompt for prohibited keywords or semantic intent. Second, if a prompt passes, the resulting image is scanned by a visual checker before being displayed to the user.

Attacking these systems is difficult because they typically operate as "black boxes" that provide only binary feedback: the prompt is either accepted or denied. This lack of continuous feedback prevents the use of standard gradient-based optimization. Consequently, previous attacks have relied on word-level enumeration or random swapping, which are computationally expensive and often produce "gibberish" prompts that are easily flagged by human moderators or perplexity-based detection systems.

The UPAM Framework

The Unified Prompt Attack Model (UPAM) addresses these challenges by treating the attack as a two-stage optimization problem. It utilizes a frozen Large Language Model (LLaMA) enhanced with a learnable Low-Rank Adaptation (LoRA) adapter to generate prompts.

Sphere-Probing Learning (SPL)

To overcome the lack of gradient information from binary filters, UPAM introduces Sphere-Probing Learning (SPL). When an API denies a prompt, SPL samples multiple points on a high-dimensional "sphere" surrounding the current prompt parameters. By observing which points pass the filter and which are denied, the model identifies the decision boundary of the safety mechanism. This allows UPAM to calculate a gradient direction, nudging the prompt toward the "Pass" zone while remaining as close to the boundary as possible—the region where harmful content is most likely to be generated without triggering a block.

Semantic-Enhancing Learning (SEL)

Once a prompt successfully bypasses the textual filter, the goal shifts to ensuring the generated image actually contains the target "harmful" concept. Semantic-Enhancing Learning (SEL) fine-tunes the LoRA adapter using CLIP-based losses. This maximizes the semantic similarity between the generated image and the intended (but restricted) concept, ensuring the attack is not just successful in bypassing filters but also effective in its generative goal.

Gradient Harmonization (GH)

A common issue in multi-objective optimization is that improving one metric (semantic similarity) might degrade another (filter bypass). UPAM employs Gradient Harmonization (GH) to project the semantic gradients in a way that does not conflict with the safety-bypass direction, ensuring the prompt remains in the "Pass" zone during fine-tuning.

Experimental Evaluation

The researchers evaluated UPAM against black-box implementations of DALL·E, DALL·E 2, and Imagen, using 10 classes from the Microsoft COCO dataset (e.g., knife, wine glass, boat) as proxies for harmful content to maintain ethical research standards.

Effectiveness and Efficiency

UPAM demonstrated a significant performance leap over existing baselines such as RIATIG and HiddVocab. In standardized testing protocols, UPAM achieved an R-precision (a measure of how often the target concept was successfully generated) of approximately 38-40%, whereas the best baseline struggled to reach 8%.

Furthermore, UPAM is remarkably efficient. While enumeration-based methods often require 300 to 600 seconds to find a successful prompt, UPAM generates an effective attack in roughly 5 seconds.

Stealth and Naturalness

Because UPAM optimizes the weights of an LLM rather than individual characters or words, the resulting prompts are grammatically correct and semantically coherent. Perplexity (PPL) scores, which measure how "natural" text appears to a language model, were significantly lower for UPAM (~700) compared to baselines (~3000+). This makes UPAM's adversarial prompts nearly indistinguishable from legitimate user queries, allowing them to bypass human moderation and automated perplexity checks.

Conclusion and Future Work

UPAM represents a significant advancement in the red-teaming of T2I models, demonstrating that dual-layered defenses can be bypassed efficiently using LLM-guided optimization and boundary-probing techniques. While the study used proxy concepts for ethical reasons, the underlying methodology highlights a critical vulnerability in current safety architectures. The authors emphasize that this research is intended to assist developers in creating more robust defenses, such as adversarial training and improved semantic filters, to stay ahead of increasingly sophisticated prompt-based attacks.

Summary updated

BibTeX
@inproceedings{peng2024upam,
  author = {Duo Peng and Qiuhong Ke and Jun Liu},
  title = {{UPAM: Unified Prompt Attack in Text-to-Image Generation Models Against Both Textual Filters and Visual Checkers}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=KU9mn6deDR},
}
Figure