Empirical reproduction and test harness for W3C Web Machine Learning CG: WebMCP Issue #288.
This repository provides a reproducible minimal testbed demonstrating why event.isTrusted and navigator.userActivation cannot protect "propose-then-confirm" WebMCP applications against autonomous computer-use or browser-use agent self-approval.
This research is documented across a two-part engineering deep dive:
-
Part 1: An Engineer's Guide to WebMCP in Chrome 156
(Also published on Dev.to & GitHub Gist)
How in-browser tool registration (document.modelContext) works, remote MCP comparison, schemas, tool annotations, and Permissions-Policy isolation. -
Part 2: The Self-Approval Paradox: Why
isTrustedanduserActivationFail Against Computer-Use Agents
(Also available as a GitHub Gist)
Detailed analysis of W3C Issue #288, the CDP native input simulation, the Chrome 156 trace logs, and proposed platform mitigations.
When web applications expose JavaScript tools to in-browser agents via document.modelContext.registerTool(...), consequential operations (e.g. purchasing, funds transfer, database writes) typically follow a propose-then-confirm pattern:
- The agent calls a tool (e.g.
propose_order), which stages the action, creates a pending order, and renders an "Approve" button into the DOM. - The tool invocation resolves with
{ status: "pending_approval" }. - The page expects a human operator to review the UI and click "Approve".
The Flaw: If the agent host can both execute WebMCP tools and drive browser input (via CDP, WebDriver, or OS accessibility events), the agent can simply locate the confirmation button on the page and click it itself.
sequenceDiagram
autonumber
participant Host as Agent Host (CDP / Computer-Use)
participant WebMCP as WebMCP (document.modelContext)
participant DOM as Page DOM (<button id="approve">)
participant Backend as Application State
Host->>WebMCP: executeTool("propose_order", { sku, qty })
WebMCP->>Backend: Create pending order
Backend-->>WebMCP: { status: "pending_approval", orderId: "ord_0001" }
WebMCP-->>DOM: Render "Approve Order" button
WebMCP-->>Host: Tool returns status: "pending_approval"
Note over DOM: Expected: Human operator confirms
Host->>DOM: Dispatches native click (CDP Input.dispatchMouseEvent)
Note over DOM: Event isTrusted: true, userActivation.isActive: true!
DOM->>Backend: Order approved & finalized without human intervention
A common proposal in discussions was to require page-side confirmation buttons to verify event.isTrusted or navigator.userActivation.isActive:
document.getElementById("approve-order").addEventListener("click", (event) => {
if (!event.isTrusted) return; // Attempt to block script automation
if (!navigator.userActivation.isActive) return; // Attempt to enforce user activation
finalizeOrder();
});Our empirical tests against Chrome 156 (156.0.8078.48) reveal why this assumption fails:
| Dispatch Method | event.isTrusted |
navigator.userActivation.isActive |
Page Validation Result |
|---|---|---|---|
CDP Input Pipeline (Input.dispatchMouseEvent) |
true |
true |
approved (Agent successfully self-approves) |
DOM Script Call (element.click()) |
false |
false |
rejected (untrusted_event) |
event.isTrustedonly separates script calls (element.click(),dispatchEvent()) from browser input pipeline events. Because autonomous agents and computer-use systems dispatch input through the browser's native input pipeline, their events are stampedisTrusted: trueby construction.navigator.userActivationis minted directly when native input events are received.
index.html: Minimal WebMCP demo catalog registering tools ondocument.modelContextand rendering a protected approval control inside adata-webmcp-user-decisioncontainer.driver.mjs: Standalone Node.js driver that launches Chrome with--enable-features=WebMCP, calls the tool via CDP, executes a synthetic input click, and records the event log.trace-run-02.json: Actual recorded JSON event trace demonstrating self-approval.
- Google Chrome 156+ (supports the WebMCP origin trial / flag).
- Node.js 18+ with native
WebSocketandfetchsupport.
git clone https://github.com/Ayoola-tech2024/webmcp-self-approval-demo.git
cd webmcp-self-approval-demo
npm test(Optional: specify custom Chrome binary path via CHROME_PATH="path/to/chrome" npm test)
As posted to W3C WebML WebMCP Issue #288:
- Host Non-Synthesis Rule: The specification should normatively require that conforming agent hosts must not dispatch input into a document while an action initiated by that agent is awaiting decision on the page.
- Element-Level Markers: Decision boundaries should be designated at the DOM container level (
data-webmcp-user-decision), allowing one approval UI to cover multi-tool batches. - Normative Security Clarification: Explicitly state that DOM confirmation UI is not an agent security boundary when the host has DOM-automation capabilities.
MIT © Ayoola-tech2024