TopicAttack: An Indirect Prompt Injection Attack via Topic Transition

Yulin Chen, Haoran Li, Yuexin Li, Yue Liu, Yangqiu Song, Bryan Hooi

Introduction

As Large Language Models (LLMs) are increasingly integrated into real-world applications—ranging from search engines like Perplexity to personal assistants like Microsoft Copilot—they have become reliant on retrieving external data to provide accurate, up-to-date information. However, this reliance introduces a critical vulnerability: Indirect Prompt Injection (IPI). In an IPI attack, a malicious actor embeds instructions within a third-party source, such as a website or document, which the LLM then retrieves and executes as if it were a direct command from the user.

While traditional IPI methods often rely on "abrupt" commands, modern LLMs are increasingly resilient to these sudden shifts in context. This paper introduces TopicAttack, a novel technique that utilizes smooth, fabricated conversational transitions to bypass state-of-the-art safety filters and instruction-following defenses.

The Problem: The "Abruptness" Signal

Current LLM safety training is highly effective at identifying out-of-context instructions. For instance, if a user asks for a summary of a historical document and the retrieved text suddenly commands the model to "DRAFT AN AD FOR STARBUCKS," the model recognizes this as a deviation from the user's intent and ignores it. This "topic gap" serves as a primary signal for safety filters. To succeed, an attacker must make the malicious payload appear plausible within the flow of the retrieved content.

The TopicAttack Framework

TopicAttack addresses the limitations of abrupt injections by employing a two-pronged strategy designed to deceive the model's internal attention mechanisms.

1. Smooth Topic Transition

Instead of a single command, TopicAttack injects a fabricated multi-turn dialogue history. Using an auxiliary LLM (such as GPT-4o), the attacker generates a conversation that begins with the benign topic requested by the user and gradually pivots toward the malicious goal.

For example, if the retrieved context is about the geography of a specific city, the injected dialogue might transition from land area to local businesses, then to coffee culture, and finally to a command to generate a specific advertisement. By minimizing the semantic gap between the benign context and the malicious instruction, the attack becomes indistinguishable from legitimate data to the model's safety layers.

2. Attention Maintenance (The Reminding Prompt)

To ensure the model remains focused on the malicious task—even when the system prompt attempts to "remind" the model to follow only the user's original query—TopicAttack includes a "reminding prompt." This meta-instruction tells the LLM to ignore subsequent system markers or instructions, effectively neutralizing defenses like the "Sandwich" method (where user instructions are repeated at the end of the prompt).

Additionally, the researchers utilize the "OK" Trick: prepending a fabricated assistant response (e.g., "Assistant: OK") at the start of the injection. This tricks the model into believing the user's original request has already been satisfied, clearing the way for the new, malicious instruction.

Experimental Evaluation

The researchers evaluated TopicAttack across several rigorous benchmarks:

  • Inj-SQuAD & Inj-TriviaQA: Standard Question Answering datasets modified with injected instructions for phishing, advertising, or propaganda.
  • InjectAgent: A dataset designed for LLM agents, where the goal is to force the model to invoke dangerous tools, such as unauthorized financial transfers or system access.

The attack was tested against leading models, including Llama 3, Qwen 2, and GPT-4o.

Key Results and Insights

TopicAttack demonstrated overwhelming effectiveness, consistently achieving an Attack Success Rate (ASR) of over 90% across most scenarios.

Bypassing Advanced Defenses

Perhaps most significantly, TopicAttack proved resilient against specialized defenses such as StruQ and SecAlign. These defenses are specifically designed to force models to prioritize authorized instructions over retrieved data. While baseline "abrupt" attacks saw their success rates drop to near 0% against these defenses, TopicAttack maintained success rates above 90%.

Attention Hijacking

By analyzing Attention Scores, the researchers found that TopicAttack significantly increases the model's internal focus on the injected tokens. The success of the attack is directly correlated with this ratio; by smoothing the transition, the attacker effectively hijacks the model's attention, making the malicious instruction appear as the most relevant next step in the conversation.

Conclusion

TopicAttack reveals a fundamental fragility in current LLM safety paradigms. It demonstrates that semantic smoothness and conversational plausibility can effectively neutralize sophisticated instruction-following defenses.

Future work must move beyond simple keyword filtering or "sandwiching" techniques. The authors suggest that the next generation of defenses must focus on developing a robust, non-bypassable instruction hierarchy that allows models to fundamentally distinguish between "user-provided commands" and "retrieved data content," regardless of how naturally that data is presented.

Summary updated

BibTeX
@misc{chen2025topicattack,
  author = {Yulin Chen and Haoran Li and Yuexin Li and Yue Liu and Yangqiu Song and Bryan Hooi},
  title = {{TopicAttack: An Indirect Prompt Injection Attack via Topic Transition}},
  year = {2025},
  eprint = {2507.13686},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.13686},
}
Figure