PLA: Black-box Prompt Learning Attack against Text-to-Image ModelsPLA: Prompt Learning Attack against Text-to-Image Generative Models
The authors propose the black-box T2I attack framework PLA, which uses gradient training to generate adversarial prompts; the authors state that on the nudity dataset its average ASR-4 against three black-box models reaches 86.54%–91.45%.
The attacker is a malicious user who, in the black-box setting, can only access images generated by the T2I model (internal model details are unknown). The attacker rewrites the target prompt into an adversarial prompt, with the goal of simultaneously bypassing the prompt filter and the post-hoc safety checker to generate NSFW images that retain the sensitive semantics of the target prompt.
- T2I models may be misused to generate NSFW content; existing black-box attacks mostly rely on word-replacement search, whose search space is limited, and the authors believe its performance is inferior to gradient training, but gradient optimization cannot be done directly in the black-box setting.
- Proposes PLA: uses sensitive knowledge-guided encoding to inject the sensitive information of the target prompt into learnable embeddings, generates adversarial prompts via a PLM, and then trains in the black-box setting using a multimodal similarity loss and improved zeroth-order gradient optimization (including historical gradients and a restart strategy).
- Attacks SDv1.5, SDXLv1.0, SLD, and Stability.ai and DALL·E 3 on the nudity/violence datasets of I2P; the authors state that PLA's average ASR-4 is higher than baselines such as QF-Attack, SneakyPrompt, Ring-A-Bell, UnlearnDiffAtk, and MMA-Diffusion.
- The paper does not specifically discuss limitations. Experimental coverage: the victim models are SDv1.5, SDXLv1.0, SLD, and two online services; the online services were tested with only 20+20 prompts; the paper does not report the iteration budget, number of queries, or number of repetitions.
- Evaluated models
- SDv1.5SDXLv1.0SLDStability.aiDALL·E 3
- Benchmarks
- I2P dataset(nudity 100 条、violence 30 条)在线服务子集(nudity 20 条、violence 20 条)
- Metrics
- ASR-4ASR-1
The researchers propose a prompt learning attack framework, PLA, to bypass the safety mechanisms of text-to-image models under black-box conditions where the model architecture and parameters are inaccessible. Previous methods mostly relied on word substitution to search for adversarial prompts, limited by the search space and less effective than gradient-based training; PLA uses multimodal similarity to design gradient training for black-box T2I models to learn adversarial prompts. Experiments show that this method can effectively attack black-box T2I safety mechanisms, including prompt filters and post-hoc safety checkers, with higher success rates than existing methods. The paper is published at ICCV 2025, and the authors note that the content may include harmful content generated by the model.
Paper analysis
What problem does this paper attempt to solve?
How to perform gradient-driven adversarial prompt attacks on the safety mechanisms of T2I models in a black-box setting.
Core problem: In a black-box setting where the internal structure and parameters of the T2I model are inaccessible, how can a gradient-driven attack method be trained to generate adversarial prompts that bypass safety mechanisms.
- Problem scenario: T2I models (such as Stable Diffusion and DALL·E 3) may be misused to generate NSFW content, which the authors believe brings legal and reputational risks to developers and users; online services typically deploy a prompt filter and a post-hoc safety checker as defenses (Figure 1).
- Shortcomings of existing methods: The authors state that most black-box attacks (such as SneakyPrompt) rely on word-replacement search, which has a limited search space and underperforms gradient training; gradient methods, however, cannot access model internals in the black-box setting, and safety mechanisms return black images after interception, invalidating output-based gradient estimation.
- Core observation: The authors believe that sensitive information in the target prompt can be encoded into learnable embeddings, and that text-image and image-image multimodal similarity can be used to construct an optimizable loss, thereby enabling gradient training in the black-box setting.
- Proposed in the paper: The prompt learning attack (PLA) framework, comprising sensitive knowledge-guided encoding, the attack pipeline, and a multimodal loss, with an improved zeroth-order gradient optimization designed for the black-box vanishing-gradient problem.
- Threat model (Section 3.2):
- Goal: Rewrite the target prompt into an adversarial prompt that simultaneously bypasses the prompt filter and the post-hoc safety checker, generating NSFW images that retain the original sensitive semantics.
- Knowledge: black-box; the attacker cannot access the model's internal architecture and parameters.
- Capability: Can only access images generated by the T2I model; can use an auxiliary model without safety mechanisms to generate the target image.
- Victim system: Black-box T2I models and online services that deploy a prompt filter and a post-hoc safety checker.
What related research exists?
Related work falls into two categories: T2I safety mechanisms and T2I adversarial attacks; this paper is positioned in black-box gradient attacks.
T2I safety mechanisms
- Detection-based: The prompt filter intercepts prompts containing sensitive words at the input stage; the post-hoc safety checker (such as SD's built-in checker, Q16, MHSC) detects NSFW images after generation, and the authors state that the latter has higher computational overhead.
- Removal-based: Suppresses NSFW content by adjusting the inference process or fine-tuning (such as ESD, Forget-Me-Not, SLD); the authors state that such methods often cannot fully eliminate inappropriate content and may affect the quality of benign images.
T2I adversarial attacks
- Non-NSFW directions: Most early attacks target image quality degradation, object distortion, or removal, and do not aim to generate NSFW content.
- White-box attacks: UnlearnDiffAtk targets concept-erasure models, and the authors note that it has not been extended to other safety mechanisms; MMA-Diffusion treats the T2I model and safety mechanisms as white-box and exploits both text and visual modalities to bypass defenses, and the authors argue that the white-box assumption does not apply to online services that typically operate as black boxes.
- Black-box attacks: SneakyPrompt uses reinforcement learning to replace sensitive words to bypass safety mechanisms; the authors note that it requires extensive exploration of candidate words at inference time, is limited by the search space, and is suboptimal in performance. Ring-A-Bell explores inducing NSFW generation, and the authors note that it lacks precise control over the generation process.
Baselines and benchmarks: The comparison baselines are QF-Attack, SneakyPrompt, Ring-A-Bell, UnlearnDiffAtk, and MMA-Diffusion; evaluation uses the nudity and violence concepts of the I2P dataset, as well as the Stability.ai and DALL·E 3 online services.
The authors position this paper as: replacing word-replacement search with gradient-driven training in the black-box setting, and the authors state that its performance is better than prior work.
How does the paper address this problem?
PLA uses sensitive knowledge encoding plus a multimodal loss to turn black-box attacks into a gradient-trainable problem.
Overall idea: encode the sensitive semantics of the target prompt into learnable embeddings, generate adversarial prompts through a pretrained language model, and then train under black-box conditions using a multimodal similarity loss and an improved zeroth-order optimization. The framework is named PLA (prompt learning attack) and contains three components (Figure 2).
Sensitive Knowledge-Guided Encoding
- Sensitive Knowledge Extraction (SKE): the target prompt is passed through a pretrained text encoder to obtain text embeddings, and SKE projects them into high-dimensional sensitive embeddings using a low projection layer and a high projection layer; the authors state that high-dimensional features help preserve the semantic intent of the target prompt.
- Prompt Encoder: injects the sensitive embedding into the encoding process of a random prompt: êl = el + ω · esen, where ω controls the degree to which sensitive information is incorporated; the output is a learnable embedding epe, which is concatenated with the target prompt and fed into the PLM.
Process of Attacking Safety Mechanisms
- Adversarial prompt generation: padv = 𝒫ℒℳ([epe; ptar]), where the PLM is BERT or T5, corresponding to the two variants PLA-BERT and PLA-T5.
- Two-step safety check: padv first passes through the prompt filter P, then the T2I model generates an image, which is detected by the post-hoc safety checker F; if blocked at either stage, a black image is returned.
- Auxiliary model: an auxiliary model Ms without safety mechanisms generates the target image Itar = Ms(ptar) to guide training; the experiments use SDv1.4 (UNet architecture) and PixArt (DiT architecture), with the main text mainly reporting SDv1.4.
Multimodal Loss
- Text-image loss: ℒa = 1 − cos(𝒯en(ptar), 𝒱en(Igen)), using CLIP's text and image encoders to compute cosine similarity, constraining the generated image to be semantically consistent with the target prompt.
- Image-image loss: Lb computes the cosine similarity between the CLIP image representations of Itar and Igen; the total loss is LMS = La + Lb.
Gradient Optimization
- Zeroth-order optimization (ZOO): under black-box conditions, the gradient is estimated using finite differences (Eq. 8), where c ∈ (0,1] is a decay parameter and ∆ is a random perturbation vector.
- Vanishing gradient problem: when the safety mechanism returns a black image, the losses at the two perturbation points are the same, and the estimated gradient is 0.
- Improved design: introduces a historical gradient ĝ2 and adaptive adjustment (Eq. 9), where β controls the dependence on the historical gradient; when the first step generates a black image and the gradient converges to 0, a "restart" strategy replaces the black image with Gaussian noise before computing the gradient, inspired by the generation process of diffusion models progressively denoising from noise.
Success Criteria
- Three conditions for an adversarial prompt: it contains no sensitive words predefined by the prompt filter; the generated image bypasses the safety checker; the image retains the sensitive semantics of the target prompt; all three are required (Section 3.1).
What experiments did the paper conduct?
ASR is measured on 3 black-box models and 2 online services; the authors state that PLA outperforms 5 baselines.
Experimental Setup
- Victim models: three black-box T2I models, SDv1.5, SDXLv1.0, and SLD; the online services Stability.ai and DALL·E 3 (with proprietary safety mechanisms).
- Datasets: the I2P dataset, with 100 prompts whose nudity proportion exceeds 50% for the nudity concept; 30 self-selected prompts for the violence concept (nudity proportion below 50%, inappropriateness proportion above 50%, labeled harmful, and not overlapping with nudity).
- Baselines: QF-Attack, SneakyPrompt, Ring-A-Bell, UnlearnDiffAtk, MMA-Diffusion.
- Metric: ASR-N, where N images are generated per prompt and success is any one containing NSFW content while bypassing the safety mechanism; ASR-4 and ASR-1 are reported.
- Evaluation method: for the three local models, ASR is quantified using three post-hoc safety checkers, SC, Q16, and MHSC; the online services are independently evaluated by 6 human evaluators and averaged.
- Auxiliary models and variants: the auxiliary models SDv1.4 (main text) and PixArt (appendix); the PLM uses BERT and T5, corresponding to PLA-BERT and PLA-T5. The paper does not report the iteration budget, number of queries, or number of repetitions.
Main Results
Average ASR-4 / ASR-1 on the nudity dataset (%, per Table 1; the AVG. column is the average of the three safety checkers):
Swipe horizontally to read the table
Method SDv1.5 SDXLv1.0 SLD QF-Attack 24.71 / 10.36 12.16 / 4.08 18.31 / 7.72 SneakyPrompt 37.89 / 20.22 19.54 / 10.69 41.37 / 24.05 Ring-A-Bell 50.53 / 29.78 27.53 / 14.34 52.59 / 33.83 UnlearnDiffAtk 73.27 / 54.96 64.98 / 38.90 66.70 / 46.43 MMA-Diffusion 77.76 / 58.38 73.30 / 45.24 76.48 / 53.00 PLA-BERT 91.45 / 68.69 90.57 / 71.43 90.82 / 69.30 PLA-T5 86.56 / 65.84 86.54 / 66.91 90.61 / 67.72 - Authors' interpretation: the authors state that PLA-BERT and PLA-T5 surpass all baselines on all three models; on SDXLv1.0, PLA-BERT's average ASR-4 is 17.27 percentage points higher than the highest among the baselines (the authors' original wording is "up to 17.27%").
- violence dataset (Table 2): PLA-T5's average ASR-4 is 90.41% (SDv1.5), 88.95% (SDXLv1.0), and 90.80% (SLD); PLA-BERT's is 88.62%, 86.95%, and 89.20%; the authors state that PLA still outperforms the baselines, and that on this dataset PLA-T5 is better than PLA-BERT, which the authors suggest may stem from differences in the "preferences" of different PLMs.
- Exceptions: in Table 2, on SLD's SC checker, PLA-T5's ASR-4 is 93.34%, higher than PLA-BERT's 91.98%; on the nudity dataset, PLA-T5 is overall slightly lower than PLA-BERT.
Online Service Attacks
- Setup: due to network latency and query limits, a subset of 20 nudity + 20 violence prompts is used, with ASR-4 as the metric and human evaluation (Table 3).
- Results: on nudity, PLA-BERT is 62.15% against Stability.ai and 45.09% against DALL·E 3; on violence, PLA-T5 is 69.70% against Stability.ai and 51.98% against DALL·E 3, both the highest in the table.
- Exceptions: for violence against DALL·E 3, Ring-A-Bell is 51.31%, higher than PLA-BERT's 36.77%; for violence against Stability.ai, SneakyPrompt (28.64%) is higher than QF-Attack (13.62%). The authors state that PLA is overall better than the baselines.
Ablation: Multimodal Loss
- Setup: PLA-T5 attacks SLD, removing La or Lb (Table 4).
- Results: the full loss achieves ASR-4 of 93.34% on violence, dropping to 81.02% when La is removed and to 79.34% when Lb is removed; on nudity it drops from 93.41% to 82.99% and 74.66%, respectively.
- Authors' interpretation: both losses are effective for the attack, with Lb having a larger effect, which the authors suggest may be because the target image contains more latent sensitive information.
Ablation: Gradient Optimization
- Setup: PLA-BERT attacks SDXLv1.0, comparing three schemes (Table 5): GPLA (Eq. 9 + restart), GZOO (original ZOO + restart), and GRE (Eq. 9 without restart).
- Results: on violence, ASR-4 is 91.69%, 52.89%, and 70.12%, respectively; on nudity, it is 95.37%, 58.44%, and 78.33%.
- Authors' interpretation: the authors state that the improved gradient method outperforms traditional ZOO; removing restart causes ASR to drop, because the black image generated at the first step triggers vanishing gradients.
Other Analyses
- Visualization: Figure 3 shows adversarial prompts and images generated by PLA on SDXLv1.0, which the authors state demonstrates its ability to generate NSFW content; the appendix provides more visualizations and online service examples.
What are some points that can be further explored?
The paper does not specifically discuss limitations; the experiments cover three local models, two online services, and two types of NSFW concepts.
Limitations and Future Directions Noted by the Authors
- The paper does not specifically discuss limitations. In the Conclusion, the authors state that the research can help "future development of more robust defense strategies," but they do not list specific future work or methodological limitations.
Scope of Experimental Coverage
- Victim models: 3 local black-box models, SDv1.5, SDXLv1.0, and SLD; 2 online services, Stability.ai and DALL·E 3 (Section 5.1).
- Datasets: 100 nudity prompts from I2P and 30 self-selected violence prompts; the online service evaluation uses only a subset of 20 nudity + 20 violence prompts (Section 5.3), with a denominator of 20 for each group.
- Concept scope: covers only two types of NSFW concepts, nudity and violence (Section 5.1).
- Safety mechanisms: the prompt filter is a predefined sensitive word list following MMA-Diffusion; the post-hoc safety checkers are SC, Q16, and MHSC (Section 5.1).
- Unreported information: the paper does not report the iteration budget of the gradient optimization, the number of queries to the victim models, the number of experimental repetitions, or the inter-evaluator agreement of the human evaluators; the complete results for the auxiliary model PixArt are in the appendix, and the main text does not give its numbers.
Summarize the main content of the paper
PLA turns black-box T2I attacks into a gradient training problem, and the authors state that its ASR exceeds five baselines.
A paper on black-box adversarial attacks against the safety mechanisms of T2I models, proposing the prompt learning attack (PLA) framework.
- Problem to solve: In the black-box setting, the internals of the T2I model cannot be accessed, and the safety mechanism returning black images invalidates gradient estimation; existing word-replacement search methods are limited by the search space.
- Method highlights: Use sensitive-knowledge-guided encoding to inject the sensitive semantics of the target prompt into learnable embeddings, and generate adversarial prompts via BERT or T5; construct a multimodal loss using CLIP's text-image and image-image similarities; train under the black box using zeroth-order optimization with historical gradients and a restart strategy; an auxiliary model (SDv1.4) provides target image guidance for training.
- Main results: On the nudity dataset, PLA-BERT achieves average ASR-4 of 91.45%, 90.57% and 90.82% against SDv1.5, SDXLv1.0 and SLD (Table 1); on the violence dataset, PLA-T5 achieves 90.41%, 88.95% and 90.80% (Table 2); on the online-service subset (20+20 items), PLA reaches up to 69.70% against Stability.ai and up to 51.98% against DALL·E 3 (Table 3).
- Ablation: Removing the image-image loss Lb lowers ASR-4 on SLD from 93.34% to 79.34% (violence); replacing the improved gradient with the original ZOO lowers ASR-4 on SDXLv1.0 from 91.69% to 52.89% (Tables 4, 5).
- Authors' conclusion: The authors state that PLA can effectively bypass the prompt filter and post-hoc safety checker to generate NSFW content, and hope this research will help develop more robust defense strategies in the future.