SurrogatePrompt: Bypassing the Safety Filter of Text-to-Image Models via Substitution

Zhongjie Ba, Jieming Zhong, Jiachen Lei, Peng Cheng, Qinglong Wang, Zhan Qin, Zhibo Wang, Kui Ren

TL;DR

Researchers have developed SurrogatePrompt, a systematic framework that bypasses the safety filters of state-of-the-art text-to-image (T2I) models like Midjourney. By strategically substituting sensitive keywords with "surrogate" terms that the filter deems safe but the generative model interprets as harmful, the team achieved bypass rates as high as 88% for generating photorealistic, unsafe content.

What Problem Does This Paper Address?

As text-to-image models like DALL·E 2 and Midjourney become more capable of producing photorealistic imagery, the risk of generating "Not-Safe-For-Work" (NSFW) content—ranging from explicit adult imagery to violent political misinformation—has skyrocketed. To combat this, service providers implement safety filters.

However, these filters are often "black boxes" that operate on a different logic than the underlying generative model. The authors identify a fundamental knowledge discrepancy: safety filters are typically trained on human-defined criteria of "safety," whereas the generative models learn raw semantic associations from massive, uncurated datasets. This paper explores how to exploit this gap to generate harmful content that current safeguards are blind to.

Methods

The core of the attack is substitution. If a prompt like "Donald Trump covered in blood" is banned, the attacker finds a surrogate that retains the harmful semantics but evades the filter. The authors propose a three-pronged automated pipeline to find these surrogates:

  1. LLM-based Substitution: Using large language models (like ChatGPT) to generate alternative expressions. For example, asking "What liquids look like blood?" might yield "red paint" or "red food coloring," which the filter may ignore but the T2I model will render as visually identical to blood.
  2. Image-to-Text (img2txt) Exploitation: The researchers found that Midjourney’s own /describe module (which transcribes images into text) is highly trusted by its safety filter. By feeding a blurred or noisy NSFW image into this module, they can extract "safe-looking" text descriptions that, when re-fed into the generator, reproduce the original NSFW content.
  3. Image-to-Image (img2img) Amplification: Once a "safe" prompt successfully generates a borderline image, the authors use Midjourney’s internal "Make Variations" or "/blend" features to iteratively amplify the NSFW elements, bypassing the more stringent filters applied to initial text prompts.
Figure 3: The SurrogatePrompt Pipeline. The shaded area represents the attack pipeline, while the remaining sections, marked with index numbers, depict the automated prompt construction pipelines. Within Part 1, a large language model (LLM) is employed to generate alternative expressions as substitutes for sensitive portions of a problematic prompt. In Part 2, Midjourney’s image-to-text module is leveraged to acquire additional prompt variations. Lastly, in Part 3, Midjourney’s image- to-image component is utilized to generate variant forms of NSFW images.

Datasets

The study did not introduce a new large-scale benchmark dataset but rather utilized several existing sources and custom-crafted prompt sets for evaluation:

  • Lexica & Erotic Spell: Used to source baseline "common" NSFW prompts to test Midjourney's default defenses.
  • I2P Dataset: Mentioned as a standard for evaluating inappropriate content in Stable Diffusion.
  • Custom Political/Violent Prompts: A set of 276 prompts combining 23 specific political actions/events with signal words (gun, blade, blood) to test bypass rates.
  • Evaluation Tools: They used the CLIP-based-NSFW-Detector, Q16 binary classifier (for violence/gore), and Arcface (to measure facial similarity to real politicians).

Key Insights and Ideas

  • The "Trusted Source" Vulnerability: One of the most striking findings is that safety filters are less suspicious of text generated by the model's own internal modules (like img2txt). This creates a circular vulnerability where the model's own "understanding" of an image is used to trick its gatekeeper.
  • Semantic Sleight of Hand: The attack works because the latent space of the generative model is dense. The embedding for a "safe" surrogate like "red paint" is often neighbor to "blood." While the filter sees a harmless art supply, the generator sees the visual texture of gore.
  • Negative Prompting as an Attack Vector: The researchers used Midjourney’s --no parameter (intended to exclude items) to actually induce nudity. By prompting for a woman in a bikini and adding --no fabric, they effectively forced the model toward explicit content while the text prompt remained technically "safe."

Key Results

The SurrogatePrompt framework proved highly effective against Midjourney, which is generally considered to have more robust defenses than open-source alternatives:

  • Violent Political Content: Achieved an 88% bypass rate for prompts depicting political figures in violent scenarios (e.g., wielding weapons).
  • Gory Content: Achieved a 54.3% bypass rate for depicting political figures in bloody scenes.
  • Adult Content: Using the substitution and --no fabric strategy, the authors achieved a 100% success rate in bypassing filters to generate explicit imagery, with a fivefold increase in the likelihood of generating nudity compared to standard prompts.
  • Transferability: The authors demonstrated that these substitution strategies also worked to varying degrees on DALL·E 2 and DreamStudio (Stability AI).
Demonstration of how substitution-based prompts bypass safety filters to generate various categories of NSFW images.

Limitations and Future Work

The authors acknowledge that their attack relies on the specific "black-box" behaviors of current commercial models. As these companies update their filters (the authors responsibly disclosed their findings to Midjourney and Stability AI before publication), these specific prompts may stop working.

Future work suggests moving toward post-generation filtering—analyzing the actual pixels produced rather than just the input text—and model alignment, where the generative model's latent space is explicitly trained to decouple "safe" surrogates from "unsafe" visual outputs. However, they note that post-generation filtering adds significant latency and computational cost.

Summary updated

BibTeX
@inproceedings{ba2024surrogateprompt,
  author = {Zhongjie Ba and Jieming Zhong and Jiachen Lei and Peng Cheng and Qinglong Wang and Zhan Qin and Zhibo Wang and Kui Ren},
  title = {{SurrogatePrompt: Bypassing the Safety Filter of Text-to-Image Models via Substitution}},
  booktitle = {CCS},
  year = {2024},
  doi = {10.1145/3658644.3690346},
}
Figure