TL;DR
This paper introduces Dialogue Injection Attack (DIA), a novel black-box jailbreak paradigm that exploits Large Language Model (LLM) chat templates to inject fabricated conversation histories. By tricking models into believing they have already agreed to a malicious request or by deferring the harmful response through a word-substitution game, DIA achieves state-of-the-art jailbreak success rates on heavily aligned models like Llama-3.1 and GPT-4o while bypassing multiple defense mechanisms.
What Problem Does This Paper Address?
Most current black-box jailbreak attacks focus on single-turn interactions, attempting to pack all adversarial framing into a single prompt. However, real-world LLM deployments (like ChatGPT or Claude) operate as chatbots that maintain state by concatenating historical dialogue turns into a single text block using specific chat templates (e.g., wrapping text in special tokens like <|start_header_id|>user<|end_header_id|>).
Safety alignment techniques (like RLHF) heavily constrain the model's response distribution immediately following a malicious user prompt. The authors identify a critical gap: existing security evaluations assume that historical assistant responses cannot be manipulated by an external attacker in a black-box setting. This paper shatters that assumption, exploring how manipulating dialogue history can fundamentally alter an LLM's safety behavior.
Methods
The core mechanism of DIA is Dialogue Injection, which acts similarly to an SQL injection attack. If an attacker knows the specific chat template tokens used by the target LLM, they can manually type those tokens into a standard WebUI text box to trick the backend inference engine into treating parts of their input as prior turns from the assistant or system.
The authors propose two distinct attack strategies based on this paradigm:
- DIA-I (Refined Black-Box Prefilling): This method injects a fake history where the assistant has already uttered an affirmative phrase (e.g., "Sure, I can help you steal a bomb..."). It then appends a user command like "Continue". To generate these affirmative beginnings safely without triggering safety filters on the attacker's side, they design an Affirmative Beginning Generation Module (ABGM). ABGM translates the malicious prompt into a benign equivalent, gets a safe response prefix, and maps the benign words back to the malicious keywords using NLP tools.
- DIA-II (Deferring Answer with Free Disguise): This strategy forces the LLM to perform a word-substitution task (a "word game") before answering. The malicious intent is completely hidden in the initial prompt, and the model generates benign text first, deferring the actual harmful output to later in the generation sequence. A Similar Demonstration Generation Module (SDGM) provides in-context examples to guide the model.
Template Inference Attack (TIA)
What if the attacker doesn't know which chat template the target LLM uses? The authors introduce TIA, which sends combined "probe" prompts containing mixed template structures. By observing which tokens the LLM repeats or gets confused by, the attacker can accurately deduce the model's underlying chat template in a few tries.
Datasets
The authors evaluated their approach using three widely recognized open-source jailbreak benchmarks:
- AdvBench: 520 harmful instructions presented as imperative sentences.
- HEx-PHI: 330 harmful instructions across 11 prohibited categories embedded in complex scenarios.
- MaliciousInstruct: 100 malicious instructions structured as questions.
Key Insights and Ideas
- The "SQL Injection" of LLMs: Attackers do not need API access to manipulate chat history; simple text-based formatting in a WebUI can break the boundary between user input and assistant history if the chat template tokens are known.
- The Power of Deferral: The authors discovered a fascinating alignment vulnerability: deferred malicious responses exhibit a higher log-likelihood than immediate ones. Prepending text—even completely unrelated benign text—makes the model significantly more likely to fulfill a harmful request later in its generation cycle.
- The Usefulness vs. Safety Paradox: As model size increases within the same family (e.g., moving from Llama-3-8B to 70B), the Attack Success Rate (ASR) actually increases. Larger models have superior instruction-following capabilities, making them more adept at executing the complex word-substitution and continuation tasks required by DIA, effectively weaponizing their own intelligence against their safety filters.
Key Results
- High Success Rates on Modern LLMs: In multi-query settings (up to 10 iterations), DIA-I achieved an Attack Success Rate (ASR) of 0.89 on Llama-3.1-8B and 0.82 on GPT-4o when evaluated on AdvBench.
- Bypassing Defenses: DIA proved highly robust against five common safety guardrails, achieving near-perfect Defense Pass Rates (DPR) against OpenAI Moderation, Perplexity Filters, and Defensive Prompt Patches.
- Efficient Template Guessing: The Template Inference Attack (TIA) achieved over 90% accuracy within just 5 query attempts, making the overall attack highly practical against unknown black-box systems.
Limitations and Future Work
While highly effective, DIA relies on the assumption that the target LLM strictly adheres to standard chat template parsing without sanitizing special structural tokens at the user input boundary. If a platform strips out tokens like <|eot_id|> prior to template wrapping, the injection fails.
Future work highlights the urgent need for developers to implement strict input sanitization of chat template control tokens and to design multi-turn defense mechanisms that validate the consistency of dialogue history rather than just scanning the latest user prompt.
Summary updated