Skip to content

Understanding and mitigating role spoofing attacks in large language modelsUnderstanding and Mitigating Role Spoofing in LLMs

arXiv: Jailbreaks, Prompt Injection, Poisoning & Defenses· arXiv:2610.40396· Ezra Edelman, Benjamin Edelman, Surbhi Goel, Eran MalachUniversity of Pennsylvania; Princeton University; AppleIndexed by this site · 24 days ago· Originally publishedAttacks

Quick read

Attacks

Based on the paper PDF (AI-generated); refer to the original

The authors study role spoofing injection in LLMs: forged content and structure can deceive all tested models, and they propose using linear probes to detect the model's internal role attribution.

Threat modelThe attacker can inject text into a legitimate tool response (e.g., a malicious web page or email), impersonating the user through the content style and chat structure of forged user messages (fake special tokens), exploiting the instruction hierarchy rather than bypassing it; the AgentDojo experiments use a non-standard threat model: arbitrary text injection into tool calls is allowed and no character escaping is performed, but real special tokens cannot be injected. The victim system is an LLM agent that reads tool outputs.

Questions
When an LLM agent reads untrusted tool output, an attacker can impersonate the user to issue instructions (role spoofing), exploiting the instruction hierarchy rather than bypassing it. The authors view this as an OOD generalization failure, and all existing models are affected.
Methods
The authors combine fabricated content with fabricated structure to carry out injection, use the Who Said What setting and a two-layer toy transformer to analyze the model's role-tracking mechanism, and propose training a linear probe on activations, compared against ground-truth roles, to detect role spoofing.
Experiments and results
Injections that fabricate content plus structure deceived all tested models; the injection/control ratio on the AgentDojo workspace is 63.1%–103.6%, and on the self-built testbed the success rate exceeds 95% for all except Gemini 3.1 Pro (72.5%). The authors state that the linear probe outperforms baselines in the 0–1% FPR range and requires no injection training data.
Limitations and future work
The authors note that the probe can only detect role spoofing, not other prompt injections; the probe requires access to the model's internal activations; the AgentDojo experiments use a more permissive threat model, so results are not directly comparable to the default setting.
Experimental setupGPT-5.4、Claude Opus 4.8 et al. · AgentDojo (workspace family)、Simple Tool-Use Testbed(作者自建,5 个套件 24 个任务) et al. · injection success rate、injection-to-control ratio et al.
Evaluated models
GPT-5.4Claude Opus 4.8Claude Opus 5Claude Sonnet 5Gemini 3 ProGemini 3.1 ProGemini 3.5 FlashGemini 3.6 FlashQwen3.5-27BGemma 4 31B-IT
Benchmarks
AgentDojo (workspace family)Simple Tool-Use Testbed(作者自建,5 个套件 24 个任务)Who Said What 设置(基于 Nemotron-SFT-Agentic-v2 与 Nemotron-CC)
Metrics
injection success rateinjection-to-control ratiotrue positive rate at false positive rate 0–1%Who Said What attribution accuracy
AI summaryThe researchers propose and analyze a "role spoofing" attack against large language models: malicious text in tool output (for example, a malicious webpage visited by an Agent) impersonates the user by exploiting the model's tendency to judge the source of an utterance by writing style rather than by the labeled role. The study finds that models track "who said what" based on both content cues (semantics, writing style) and structural cues (control tokens, formatting), and are especially susceptible to attacks that forge both structure and content. In a toy setting, adversarial training that teaches the model to ignore content-based injections mitigates content attacks but does not stop structural attacks, which explains why frontier models with increased resistance to multiple injection attacks can still be fooled. The authors also propose using a linear probe to predict the role in a conversation to detect such attacks, and the paper shows the method is effective across different settings.

The researchers propose and analyze a "role spoofing" attack against large language models: malicious text in tool output (for example, a malicious webpage visited by an Agent) impersonates the user by exploiting the model's tendency to judge the source of an utterance by writing style rather than by the labeled role. The study finds that models track "who said what" based on both content cues (semantics, writing style) and structural cues (control tokens, formatting), and are especially susceptible to attacks that forge both structure and content. In a toy setting, adversarial training that teaches the model to ignore content-based injections mitigates content attacks but does not stop structural attacks, which explains why frontier models with increased resistance to multiple injection attacks can still be fooled. The authors also propose using a linear probe to predict the role in a conversation to detect such attacks, and the paper shows the method is effective across different settings.

Related events and news

1 events · 1 news mentions

News that mentions this paper

周报:预训练投毒可植入智能体后门

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    Study and mitigate role spoofing: injections in tool outputs impersonating user messages to deceive LLM agents.

    Core problem: LLMs treat fabricated "user messages" in tool outputs as genuine user instructions (role spoofing); the authors aim to understand its causes and provide a detection method.

    • Scenario and importance: When an LLM acts as an agent reading untrusted data such as emails and web pages, injected text can hijack the model into performing operations not intended by the user (e.g., transferring money). The authors consider this a class of indirect prompt injection that exploits the instruction hierarchy.
    • Existing understanding and gaps: Ye et al. (2026) proposed the concept of role confusion, holding that models judge provenance by style alone; Chang et al. (2026) demonstrated injection with fake special tokens. The authors state that these works focus on attacks and lack rigorous study of role-tracking mechanisms and effective defenses.
    • Core observation: Role attribution could in principle be solved by the simple mechanism of "the role token after the most recent special token," but within the training distribution multiple mechanisms (content-based, structure-based) can perform this task near-perfectly, so the model may learn non-robust mechanisms; the authors classify this as an OOD generalization failure.
    • Paper contributions: Systematically measure frontier models' susceptibility to role spoofing; analyze the two classes of mechanisms, content and structure, using controlled experiments and toy models; propose a detection method based on linear probes that uses ground-truth roles.
    • Threat model:
      • Goal: Make the model treat injected content as a message from a higher-privilege level (the user) and act on it.
      • Knowledge: The attacker knows the target model's chat template format (forging its textual form) but cannot inject real special tokens.
      • Capability: Inject arbitrary text into a legitimate tool response; in the AgentDojo experiments no character escaping is performed (the authors call this a more permissive attacker model).
      • Victim system: LLM agents that read tool outputs (the AgentDojo workspace environment and the authors' self-built 5-scenario testbed).
  2. What related research exists?

    Related work falls into three groups: role spoofing attacks, injection defenses (representation-based detection and architectural changes), and parallel mechanism research.

    Role Spoofing Attacks

    • Chang et al. (2026): Proposed injecting models with fake special tokens (ChatInject), tested it as a component of various prompt injections, and reported it transfers across models; the attack in this paper is similar.
    • Zhu et al. (2026), Zhou et al. (2024), Jiang et al. (2025): Used similar fake special tokens to enhance jailbreak attacks.
    • Zhan et al. (2026): Studied the same class of attack with Qwen3, Llama-3.1, GLM-4.5 and Seed-OSS, finding weaker effectiveness without real special tokens; the authors state their own results show modern LLMs (including closed-source ones) remain vulnerable under a correct implementation.
    • Ye et al. (2026): Framed prompt injection as role confusion, hypothesizing that models judge provenance by style alone; the authors state that its role probe inspired their method, but that they left it as an open question to use it as a detector.

    Defense Strategies

    • Detection based on internal representations: Anthropic (2026) used linear probes to flag injected instructions for Claude Opus 5; Abdelnabi et al. (2025) used linear probes to detect task drift; PIShield (Zou et al., 2026) trains a linear classifier on internal features of clean and injected inputs. The authors state that their method exploits ground-truth roles and outperforms these prior defenses.
    • Architectural changes: Wu et al. (2025) and Panickssery & Ackerman (2025) proposed adding role embeddings to each token; Wang et al. (2025) used positional embeddings to add separators between messages; Su et al. (2026) split different roles into separate streams. The paper notes that these works report improved injection robustness but were not tested on injection with fake special tokens.

    Parallel Work

    • Balp-Straffon et al. (2026): Used linear probes on Llama-3.1-8B and Qwen2.5-7B to predict whether the model follows the instruction hierarchy; the authors state this corroborates the predictive power of probes for such behavior.
    • Laddha et al. (2026): Used controlled experiments to study how open-source models choose which instruction to follow; the authors state its conclusions are close to this paper's: different models rely on different cues.

    Baselines and Benchmarks: The defense comparison baselines are three probes—a role probe trained in the manner of Ye et al. (2026) (best selected from over 100 hyperparameter configurations), a classifier probe trained only on content injection, and a classifier probe trained on a mixture of content injection and fake special token injection; attack evaluation uses AgentDojo (workspace family) and the authors' self-built Simple Tool-Use Testbed.

    The authors position this paper as: the focus is not on proposing a new attack but on understanding the mechanism and providing a defense based on it, and the defense does not require injection samples or coherent conversations as training data.

  3. How does the paper address this problem?

    First measure attack effectiveness, then analyze the mechanism using controlled experiments and toy models, and finally detect role confusion with linear probes.

    The overall approach has three steps: measure the role spoofing success rate in two tool-use environments; use the Who Said What setting and a two-layer toy transformer to separate the two types of role-tracking mechanisms, content and structure; and, exploiting the fact that the inference engine knows the ground-truth role, train a linear role probe to detect segments where the model's internal "belief" is inconsistent with the true role.

    Attack Construction and Success Determination

    • Attack form: inject fake special tokens imitating the chat template (in text form, treated as ordinary text by the tokenizer) into the tool response, wrapping a fabricated user message whose content imitates the style of a real user request.
    • Success determination: using the model's execution rate for the same malicious task issued directly by the real user as the control baseline, the ratio of injection success rate to control measures role spoofing itself, excluding the case where "the model would have refused the task anyway."
    • Self-built testbed: 5 scenarios (bank accounts, document editing, calendar, email, climate control), with user tasks and attack tasks randomly sampled from the same task pool (excluding cases where the two are the same); attack success is defined as the agent completing the attack task; 24 tasks, 45 tools, 15 environments, 2,208 clean instances, 10,368 injected instances (Table 4).

    Who Said What Setting

    • Task: prefill a conversation, randomly select a snippet that appears only once, and at the end ask the model whether the message containing that snippet is a tool result, comparing the "Yes"/"No" logits with the ground truth.
    • Misleading content distribution: use real agentic conversation data (Nemotron-SFT-Agentic-v2), merging multiple consecutive real messages into one message to create content misleading without structural support.
    • Fake structure distribution: fill message content with random internet text (Nemotron-CC) so that content is unrelated to the sender, and wrap injections with fake special/role tokens; for each model, select the most effective one from a set of fake styles.

    Toy Setting

    • Task: a two-layer decoder-only transformer, with message roles randomly user/assistant/tool, content sampled from four symmetric Dirichlet priors (α=0.6), and messages separated by special tokens; a prediction is defined as correct if the next-token distribution is closer under KL divergence to the correct response distribution.
    • Training procedure: pretraining (90% conversations without separators + 10% conversations with non-special structure tokens, 500 steps) → instruction tuning (clean special-token conversations, 200 steps) → adversarial post-training (mixed with content injections and correct responses, 400 steps); batch size 512, AdamW, learning rate 0.0003.
    • Three types of test injections: content-only (tool message content sampled from the user distribution), structure-only (fake structure tokens inserted at the end followed by tool-distribution content), full injection (fake structure plus user-distribution content).
    • LLM validation: LoRA fine-tuning of Qwen3.5-27B, training one version each for content injection and fake special-token injection, using 3 content injections and 4 structure injections for training and a held-out suite and injection formats for testing.

    Linear Role Probe Defense

    • Principle: the inference engine always knows the ground-truth role of each message; a linear probe is trained on model activations to predict whether each token belongs to tool output, and if the model "believes" a segment in the tool output was sent by the user, it is flagged as role spoofing.
    • Training data: synthetic conversations without injections, with turn order generated by a Markov chain and content tokens sampled uniformly from the vocabulary (excluding special tokens); 86,650 per document, 16 seeds; the input is the concatenation of activations after the decoder blocks of all layers.
    • Detection method: take the maximum probe score over any token within the tool message, with the threshold set at 0.1% FPR on clean data; the authors state that taking the maximum is to prevent attackers from diluting the average score with clean content.
    • Appendix A gives a constructive proof that a two-layer transformer can implement three role-tracking rules (content-only, trusting both real and fake structure, trusting only real structure), showing that these mechanisms are realizable within the same architecture.
  4. What experiments did the paper conduct?

    All tested models were deceived by the combined injection; toy experiments show that content-resistance training shifts models toward relying on structure; probe detection outperforms baselines.

    Experimental Setup

    • Models tested: GPT-5.4, Claude Opus 4.8, Claude Opus 5, Claude Sonnet 5, Gemini 3 Pro, Gemini 3.1 Pro (AgentDojo, Figure 1); plus Gemini 3.5 Flash (self-built testbed, Table 3); Who Said What additionally includes Gemini 3.6 Flash et al. (Figures 2, 7); mechanism validation uses Qwen3.5-27B; probe experiments use Gemma 4 31B-IT and Qwen3.5-27B.
    • Benchmarks: AgentDojo workspace family (over 100 user/attack task pairs randomly selected per model); self-built Simple Tool-Use Testbed (10,368 injection instances).
    • Metrics: Injection success rate, control success rate, and their ratio; probes use TPR in the FPR 0–1% range.
    • Judgment method: AgentDojo and the testbed judge by whether the attack task is completed; Who Said What compares Yes/No logits; the paper does not state whether an LLM judge is used.
    • Probe evaluation samples: Negative samples are 128 clean AgentDojo runs, 1,516 testbed runs, and 512 Nemotron-SFT-Agentic-v2 conversations; positive samples are injections that deceived the model at least once across 8 runs (288 + 3,621 for Gemma, 253 + 6,490 for Qwen).
    • Repetitions: Each positive injection sample is run 8 times; probe training uses 16 seeds, classifier probes use 64 seeds.

    Main Results

    AgentDojo workspace family (Figure 1 right table):

    Swipe horizontally to read the table

    ModelControlInjectionRatio
    GPT-5.449.8%47.8%96.2%
    Claude Opus 4.834.8%22.0%63.1%
    Claude Opus 528.6%29.7%103.6%
    Claude Sonnet 565.5%43.2%65.9%
    Gemini 3 Pro66.6%61.7%92.6%
    Gemini 3.1 Pro46.9%45.2%96.3%
    • The authors state that injections combining forged content and structure deceive all tested models; Opus 5's ratio exceeds 100%, but the authors note that 100% is within the error range and consider it unlikely that the model truly follows injections more than the user.
    • Self-built testbed (Table 3): injection success rates are 100% for GPT-5.4, Opus 4.8 and Opus 5, 98.8% for Sonnet 5, 98.5% for Gemini 3.5 Flash, and 72.5% for Gemini 3.1 Pro; under clean tests, all models' correct tool-call accuracy exceeds 95%.
    • The authors note that the resistance Gemini 3.1 Pro shows on the testbed does not hold under the AgentDojo setting.

    Who Said What Mechanism Experiments

    • What was measured: The model's role attribution error rate under two kinds of misleading cues, misleading content (no forged structure) and fake structure (random content), separately (Figures 2, 7).
    • Results: Different models are deceived to different degrees by the two kinds of misleading cues—the authors state that Gemini 3.6 Flash is almost never deceived by misleading content but is deceived by fake structure, whereas GPT-5.4 is more often deceived by misleading content; specific values are not labeled in the figures.
    • Authors' interpretation: Models rarely rely on a robust ground-truth mechanism but on different "mixtures" of content and structure mechanisms; the authors also state that they do not claim any model consistently relies on a fixed mixture, and that results are sensitive to query wording.

    Toy Setup and LLM Validation

    • Toy results (Figure 4): At the end of instruction tuning, the model's clean accuracy is near-perfect and it resists structure injection, but it is deceived by content injection and full injection; after adversarial training, clean and content-injection accuracy improve, but structure-injection accuracy reverses, and full injection still works (success rate drops slightly). Attention visualizations (Figures 3, 12) show that the instruction-tuned model attends to content tokens, and after adversarial training shifts to attending to the most recent role token but does not distinguish real from fake special tokens.
    • LLM validation (Table 5): The Qwen3.5-27B base model has 0.0% accuracy under content-only, native fake special token, and other fake special token injections; the content fine-tuned version reaches 100.0% on content-only, only 36.2% on other fake special token injection, and 0.0% on the native format; the structure fine-tuned version reaches 100.0% on both classes of fake special token injection and 0.0% on content-only.
    • Authors' interpretation: Training against one class of injection transfers only limitedly to the other, and structure-injection training transfers not at all to content injection.

    Probe Detection Experiments

    • What was measured: TPR of this paper's role probe versus three baselines (Ye et al.-style role probe, classifier probe trained only on content injection, classifier probe trained on mixed injection) on held-out injections (FPR 0–1%, Figure 5).
    • Results: The authors state that this paper's role probe outperforms all baselines, with the classifier probe trained only on content injection performing worse; Figure 14 shows that the probes for both models have TPR above 99% at zero false positives (as stated in the figure caption).
    • Self-attribution comparison (Table 6): When the model itself judges the provenance of a segment, both models misattribute 100% under ordinary injection, but after adding an adversarial prefix, Gemma 4 31B misattributes nearly 0% and Qwen3.5-27B only 25.0%, whereas the role probe maintains 100.0% flagging under both conditions and 0.0% false positives on clean data (1,000 conversations per condition).

    Other Ablations and Analyses

    • Under AgentDojo's default YAML escaping setting (Table 2): GPT-5.4's ratio is 86.6%, and Opus 5 does not succeed; after switching to JSON output format, GPT-5.4 is 82.6% and Opus 5 is 83.6%.
    • The authors find that the AgentDojo default runner itself can be injected, with over 60% of task pairs attackable before the agent acts, but this paper does not use such attacks.
    • The three-layer toy model and the variant with injection carried only by tools give similar results (Figures 9–11).
    • The probe performs best when trained on conversations with uniformly random tokens (the authors call this unexpected).
  5. What are some points that can be further explored?

    The authors acknowledge that the probe covers only role spoofing and requires internal activations; the experiments cover 10 models and two tool-use environments.

    Limitations and Future Directions Noted by the Authors

    • Limited detection scope (Section 4): the authors note that the probe can only detect role spoofing and cannot detect prompt injection that does not involve role impersonation.
    • Limited adversarial training transfer (Section 3.3, 4): training against one type of injection transfers poorly to another, and the authors believe that even if the training data covered all attacks in this paper, the model could still be vulnerable to more sophisticated role spoofing attacks.
    • Adding training data is a brittle solution (Conclusion): the authors consider it brittle to solve OOD failures by adding adversarial examples to the training data, which does not guarantee the model learns a robust mechanism; they also acknowledge that future models may fully solve the attacks discussed in this paper through such data.
    • Flaws of self-attribution detection (Section 4): it is computationally expensive, hard to deploy in practice, and can be bypassed by an informed attacker using instructions.
    • The authors' hope (Conclusion): they hope frontier model providers will integrate this simple scheme into models (this is a proposal, not something completed).

    Scope of Experiments

    • The attack evaluation covers 6 models (AgentDojo workspace family) and 6 models (a self-built testbed, including Gemini 3.5 Flash); the mechanism and probe experiments additionally use Qwen3.5-27B, Gemma 4 31B-IT, Gemini 3.6 Flash, etc.
    • The AgentDojo experiments use what the authors call a more permissive threat model (injections do not escape characters), and the authors explicitly state that their results are not directly comparable to the default AgentDojo setting; supplementary tests under the default YAML and JSON formats were done only with GPT-5.4 and Claude Opus 5.
    • The probe detection experiments were conducted only on two open-source models, Gemma 4 31B-IT and Qwen3.5-27B, and require access to the models' internal activations.
    • The probe's positive samples are limited to injections that fooled the model at least once in 8 runs; injections that never fooled the model were excluded.
    • The paper does not report repetition details beyond the specific number of runs per model for AgentDojo and the self-built testbed, nor does it report human evaluation or human agreement.
  6. Summarize the main content of the paper

    Role spoofing that combines fabricated content and structure can deceive all tested LLMs; the authors attribute this to non-robust mechanisms and propose probe-based detection.

    An attack–mechanism–defense paper on prompt injection in LLM agents, studying the role spoofing attack in which tool outputs impersonate user messages.

    • Problem: When agents read untrusted tool outputs, injected text can forge user messages and exploit the instruction hierarchy to make the model perform the attacker's task; the authors consider this an OOD generalization failure, because within the training distribution multiple role-tracking mechanisms all perform well.
    • Method: Measure attacks in two tool-use environments; use the Who Said What setting to separate the two classes of misleading cues, content and structure; use a two-layer toy transformer to simulate pretraining, instruction tuning and adversarial training; finally train a linear role probe to detect confusion against ground-truth roles.
    • Attack results: On AgentDojo workspace, injection/control ratios range from 63.1% (Opus 4.8) to 103.6% (Opus 5); on the self-built testbed, GPT-5.4, Opus 4.8 and Opus 5 have injection success rates of 100%, and only Gemini 3.1 Pro is at 72.5%, but it does not resist under AgentDojo.
    • Mechanism findings: Different models rely on different mixtures of content and structure mechanisms; in the toy experiments, adversarial training against content injection shifts the model toward relying on structure and it is still deceived by full injection; fine-tuning validation on Qwen3.5-27B shows the two classes of injection training do not transfer to each other (after content fine-tuning, accuracy under non-native fake special token injection is only 36.2%).
    • Defense results: The authors state that the role probe outperforms the Ye et al.-style probe and the injection classifier probe in the FPR 0–1% range, and training does not require injection samples; when an adversarial prefix bypasses self-attribution detection (Qwen3.5-27B flags only 25.0%), the probe still flags 100.0%.
    • Authors' conclusion: Role spoofing is a special case of OOD failure, and solutions that add training data are fragile; the authors acknowledge that the probe can only detect role spoofing and hope model providers will integrate the approach.

Related papers

Show 3 more papers
Read originalarxiv.org