Masking untrusted web content to secure agents against prompt injection

By redacting untrusted regions of the DOM before they reach the agent, the authors restore a trust boundary that enables provable security guarantees for web-based agents.

PaperBig Techcs.CRarXiv:2607.05277v1
Kristina Nikolić · Egor Zverev · Javier Rando · Matthew Jagielski · Edoardo Debenedetti · Florian Tramèr

ETH Zurich · ISTA · Anthropic

Research Digest··3 min read
The authors introduce Untrusted Content Masking (UCM), a defense that prevents prompt injection attacks on web agents by masking untrusted content in the Document Object Model (DOM) before the agent processes it. They show that the DOM structure alone can distinguish trusted from untrusted page regions without reading their content, enabling agents to observe and interact safely with web pages while remaining isolated from adversarial content.

What they did

The authors address the challenge of extending prompt injection defenses from text-based tool-use APIs to web agents. In text-based systems, agents rely on interface definitions and never see untrusted data, creating a clear trust boundary. Web agents, however, must observe rendered pages where trusted instructions and untrusted content are mixed — removing that boundary.

UCM exploits the structure of the DOM to distinguish trusted regions (e.g., the agent's own instructions or page chrome) from untrusted regions (e.g., user-generated content, ads). Trusted regions are defined by the page author's specification; UCM redacts untrusted regions from the DOM before the agent sees them. Interaction is routed through a sandboxed interface that enforces privilege separation: the agent can only act on trusted elements, preventing it from inadvertently following adversary-controlled prompts.

Key findings

  • UCM provably prevents prompt injection attacks where an adversary controls content on the page the agent visits, under standard security assumptions about the browser's same-origin policy and the integrity of the trusted region specification.
  • In a formal security analysis, the authors show that even if an adversary embeds malicious instructions in arbitrary page locations, UCM prevents the agent from observing or acting on them.
  • The approach works without modifying the agent's underlying language model or requiring the agent to parse untrusted content — it leverages existing DOM structure and a lightweight pre-processing step.
  • The authors demonstrate the defense on a benchmark of web agent tasks with adversarial content, showing zero success rate for attacks that would otherwise achieve over 90% task hijacking.

Why it matters

Prompt injection is a critical vulnerability for deployed web agents. By restoring a trust boundary through DOM-level masking, UCM provides a practical and provable defense that does not require modifying the agent's LLM or training. This makes it immediately applicable to existing web agent frameworks and could enable safer autonomous browsing and form-filling.

Caveats

The approach assumes a reliable mechanism to specify which DOM regions are trusted — this may be non-trivial for complex or dynamically generated pages. It also does not protect against attacks where adversarial content is injected into trusted regions (e.g., via XSS) or where the adversary controls the page's JavaScript. The defense is limited to visibility of content; it does not address attacks that exploit the agent's reasoning about structure (e.g., subtle formatting of trusted regions).

§

Analysis

This work bridges a gap in web agent security by showing that the structural properties of the DOM can substitute for the natural trust boundary present in text-based APIs. It complements other lines of defense like instruction filtering or adversarial training by providing a guarantee that does not depend on the model's robustness. The paper's formal analysis is a strong contribution, though practical deployment will depend on the ease of specifying trusted regions in real web pages — a challenge the authors acknowledge. The approach is most directly applicable to browser-based agents that parse the DOM for actions, which includes many current production systems.

newspaper

Research Digest

Articles published under the Zotpaper byline are synthesized from multiple source publications by our AI editor and reviewed by our editorial process. Each story combines reporting from credible outlets to give readers a balanced, comprehensive view.