When Context Gets Root: Privilege Escalation in LLM Harnesses
An attacker who can only write files into a repository — no jailbreak, no prompt injection, no compromised component — reliably makes six different coding agents install root CAs, exfiltrate secrets, and stand up command-and-control shells. The mechanism isn't a model failure. It's the harness.
The Problem: Defense Relies on a Label That Harnesses Rewrite
Every agent framework defends with an instruction hierarchy: system commands outrank user requests, which outrank tool output. Models are trained to obey higher-privilege text and treat tool results as data. When an agent reads a malicious README, the content enters at the tool level — where the model is trained to distrust it. But the hierarchy is only as good as the role labels the harness assigns. This paper from Nanjing University shows that harnesses silently relabel content as they reconstruct context — and that's the whole game.
The Method: Instruction Privilege Escalation
The authors map every model API message type (tool, user, system-effective) onto one privilege ladder, then show that normal harness operations lift attacker content up it. Tool-to-user escalation happens through subagent delegation: the main agent forwards a task, and the harness inserts it into the subagent's context as a user message. Persistent goals and scheduled tasks do the same — content stored at tool level is re-delivered later as user input. Tool-to-system escalation happens through custom-subagent installs: attacker-controlled config becomes system-prompt material loaded on every invocation. Crucially, no role confusion tricks the model — the harness itself assigns the privileged label, so both the working agent and the automatic permission reviewer (Auto PR) faithfully do what they were trained to.
flowchart LR
A[Tool-level repo content] --> B{Harness operation}
B -->|subagent delegation| C[User-level message to subagent]
B -->|persistent goal| D[Re-sent as user instruction]
B -->|scheduled task| E[Delivered later as user message]
B -->|custom subagent install| F[System-effective prompt]
C --> G[Working agent executes]
D --> G
E --> G
F --> G
G --> H{Auto PR reviews}
H -->|'user' role in transcript| I[Approves as user-authorized]
The motivating case is stark: told directly to start a backdoored server (tool-level), Codex GPT-5.5 refuses. Told the same thing via delegation (user-level), a subagent says "I will run the server script directly." Auto PR flags the action as high-risk but approves it — because the reconstructed transcript shows "the user explicitly approved this exact action." The labels lie; nothing else does.
The Numbers
- Baseline collapses: tool-level attacks (MCPTox, CoT Forgery, ChatInject) achieve 0/13 objectives on Claude Code, Codex, and Kimi; 1/13 on Qwen Code and OpenCode; at most 7/13 (Gemini CLI). Under Auto PR: 0/13 everywhere.
- Tool-to-user escalation: 13/13 attack objectives on all six harnesses under full access, and 13/13 on all three with Auto PR (Claude Code, Codex, Qwen Code). Once escalation lands, the follow-through attack succeeds 86.7–100% of the time.
- Tool-to-system escalation: hidden-script variant completes 13/13 objectives everywhere — 100% success under full access, and 61.9–76.5% per-attempt even under Auto PR.
- Goals and scheduled tasks: 13/13 on all four tested paths (Claude Code scheduled tasks, Codex goals, Codex + Qwen scheduled tasks under Auto PR).
Limitations — Read These First
- Coding agents only: six CLI harnesses — Claude Code, Codex, Gemini CLI, Qwen Code, Kimi, OpenCode. Browser agents, computer-use, and generalist tool agents are untested.
- The attacker knows the harness: the premise assumes the attacker knows context-construction behavior and can seed repo files the agent will read. That fits supply-chain and untrusted-repo scenarios, not every deployment.
- It's a diagnosis, not a fix: the paper formally characterizes the flaw; provenance-aware reconstruction and level-preserving delegation are implications, not validated mitigations.
- Reliability varies: per-attempt success spans 31.7–100% across harnesses — the vulnerability is universal, but exploitability per objective is model-dependent.
Why Someone Building Things Should Care
If you ship any agent with delegation, goals, or scheduled tasks, this paper is a bug class with your name on it. Every place content crosses a message-type boundary is a privilege boundary — and most harnesses treat those transitions as bookkeeping. Audit delegation as a security-sensitive operation: provenance must survive reconstruction, and Auto PR must ask where a "user" instruction came from, not just what role label it carries. The paper's cleanest lesson: the instruction hierarchy is only as strong as the harness's relabeling discipline. The model did its job. The harness undid it, faithfully.