Goal Hijacking Attack on Large Language Models via Pseudo-Conversation Injection

Zheng Chen, Buhui Yao · DOI

Abstract

Goal hijacking constitutes a critical security vulnerability in Large Language Models (LLMs), enabling adversaries to manipulate models into generating specific outputs regardless of original user inputs. Existing approaches often rely on explicit instructions, limiting effectiveness and stealth. To overcome these constraints, we introduce a novel adversarial attack technique named Pseudo-Conversation Injection (PC-Inj), exploiting vulnerabilities in conversational context handling and role identification within LLMs. PC-Inj appends fabricated conversational contexts to original user prompts, misleading models into interpreting these as completed interactions and executing subsequent malicious instructions. Experimental evaluations using mainstream platforms—including ChatGPT (GPT4o, GPT4o-mini) and TongYiQianWen (Qwen2.5)—confirm our methods significantly surpass baseline techniques. We further propose targeted defense mechanisms, highlighting an urgent need to strengthen LLM security in practical deployments.

Introduction

As Large Language Models (LLMs) are increasingly integrated into sensitive domains such as medical diagnostics and customer support, the security of these systems becomes paramount. A primary threat is "goal hijacking," a form of prompt injection where an attacker coerces the model into abandoning its intended task (e.g., "Summarize this document") in favor of a malicious objective (e.g., "Generate a phishing lure").

While developers have implemented safeguards against direct commands like "Ignore all previous instructions," LLMs remain vulnerable due to a fundamental architectural characteristic: the lack of robust internal role boundaries. Most models process an entire dialogue as a single concatenated string. This research explores how attackers can exploit this "flat text" processing to fabricate a conversation history that tricks the model into believing a previous task is already complete.

Methodology: Pseudo-Conversation Injection (PC-Inj)

The core of the PC-Inj attack is the fabrication of a dialogue history appended to the initial user prompt. By mimicking the model's chat template, the attacker inserts a fake assistant response followed by a new, malicious user instruction. This leads the model to "hallucinate" a context where the original goal has been satisfied, reducing the cognitive dissonance of switching to a new, potentially harmful task.

The researchers identified three primary construction strategies for these pseudo-conversations:

  1. Targeted Pseudo-Conversation: The attacker crafts a fake assistant response specifically tailored to the initial prompt. This is highly effective but requires prior knowledge of the user's input.
  2. Universal Pseudo-Conversation: This uses a generic, "canned" assistant refusal or neutral response (e.g., "I'm sorry, I can't answer that..."). This strategy is more versatile as it is independent of the original prompt content.
  3. Robust Pseudo-Conversation: To bypass potential filters looking for technical markers (like ChatML tags), this strategy uses natural language markers (e.g., "Assistant:") and diverse templates to simulate the conversation flow.
Overview of the three Pseudo-Conversation Injection strategies: Targeted, Universal, and Robust.

Experimental Setup

The effectiveness of PC-Inj was evaluated using the Goal Hijacking section of the Safety-Prompts dataset. To ensure the results reflected the mechanism of hijacking rather than simple refusal of toxic content, the researchers performed rigorous data cleaning. They removed existing "ignore previous" phrases to establish a clean baseline and filtered out prompts containing direct harmful content (e.g., violence). A random sample of 200 instructions was then used for testing across ChatGPT (4o and 4o mini) and Qwen 2.5.

Key Results and Analysis

The experimental results demonstrate that PC-Inj significantly outperforms traditional hijacking methods. Across all tested models, the Targeted strategy yielded the highest success rates, followed by the Universal and Robust approaches.

Quantitative comparison of PC-Inj strategies against the "ignore the previous" baseline across multiple LLMs.

Specifically, for ChatGPT 4o, the success rate increased from a baseline of 78.7% to 92.0% with the Targeted approach—a 13.3% improvement. Qwen 2.5 saw an even more significant jump, from 69.3% to 84.5% (a 15.2% increase). Even the Robust strategy, which avoids technical tags, maintained high success rates (76.5% to 85.3%), indicating that simple keyword filtering of chat markers is an insufficient defense.

Discussion: The "Flat Text" Vulnerability

The success of PC-Inj highlights a critical weakness in current LLM architectures. Despite supervised fine-tuning (SFT) intended to teach models to respect role boundaries, they still operate primarily on next-token prediction across a unified sequence. By providing a realistic "ending" to the first task, the attacker effectively resets the model's state. The model does not perceive itself as "disobeying" the initial instruction; rather, it interprets the sequence as moving naturally to the next round of a legitimate conversation. The researchers observed a "Closer is Better" rule: the more semantically consistent the fake history is with the original prompt, the more likely the hijacking is to succeed.

Conclusion and Future Work

Pseudo-Conversation Injection represents a potent and stealthy threat to LLM security. Current defenses that rely on identifying explicit "ignore" commands or filtering specific technical tags are inadequate against these context-based attacks. Future research must focus on developing "role-aware" architectures that can distinguish between system-level chat markers and user-provided text at a deeper level. Additionally, exploring more sophisticated, dynamically generated fake histories could further reveal the extent of this vulnerability.

Summary updated

Abstract

Goal hijacking constitutes a critical security vulnerability in Large Language Models (LLMs), enabling adversaries to manipulate models into generating specific outputs regardless of original user inputs. Existing approaches often rely on explicit instructions, limiting effectiveness and stealth. To overcome these constraints, we introduce a novel adversarial attack technique named Pseudo-Conversation Injection (PC-Inj), exploiting vulnerabilities in conversational context handling and role identification within LLMs. PC-Inj appends fabricated conversational contexts to original user prompts, misleading models into interpreting these as completed interactions and executing subsequent malicious instructions. Experimental evaluations using mainstream platforms—including ChatGPT (GPT4o, GPT4o-mini) and TongYiQianWen (Qwen2.5)—confirm our methods significantly surpass baseline techniques. We further propose targeted defense mechanisms, highlighting an urgent need to strengthen LLM security in practical deployments.
BibTeX
@misc{chen2025goal,
  author = {Zheng Chen and Buhui Yao},
  title = {{Goal Hijacking Attack on Large Language Models via Pseudo-Conversation Injection}},
  year = {2025},
  eprint = {2410.23678},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.23678},
}
Figure