feat(webui): require explicit confirm on WebMCP recovery tools

The three recovery tools now carry a required `confirm: true`, rejected before
the API is touched when absent. It is a deliberate-action signal, not a
security control -- an agent can pass it trivially, and the module header says
so. Its value is making the model state intent rather than reaching for a
mutation mid-sentence.

The module headers also record two things this work learned the hard way: the
API's three string/object shape traps (inputSchema and executeTool's input and
result are JSON strings, not objects), and the advisory status of the
annotations -- Chrome 152's getTools() reports only readOnlyHint and
untrustedContentHint and drops consequentialHint, and a page-invoked
executeTool gates nothing. Nothing here is enforced by the browser. The tools
run in the signed-in operator's session and cannot exceed that operator's
rights; that is the security model.
This commit is contained in:
sam committed 2026-09-22 13:57:31 +10:00
1 parent d55dedab86
commit e7d9fa2c4c
4 files changed
+77 -6

No files matched your search

+40 -2
View File
@@ -6,6 +6,19 @@
// inspection, plus the three recovery actions (retry, stop, cancel). The human
// review gate -- approve and reject -- is deliberately not exposed, because an
// agent that can approve its own work defeats the design.
//
// Security model: these tools run in the signed-in operator's own browser
// session, so they inherit exactly what that operator can already do and can
// exceed it in no way. That holds regardless of any annotation.
//
// The annotations are advisory, and today they are not enforced: Chrome 152's
// `getTools()` reports only `readOnlyHint` and `untrustedContentHint` and drops
// `consequentialHint`, so no agent sees it from discovery, and a page-invoked
// `executeTool` gates nothing. `consequentialHint` is still set on the recovery
// tools because the spec accepts it and a conforming client may honour it.
// The `confirm: true` requirement below is a deliberate-action signal, not a
// security control: an agent can pass it trivially. Its value is making the
// model state intent rather than reaching for a mutation mid-sentence.
import type { WebMcpTool } from "./webmcp";
/** The dashboard client these tools call. `ui/src/lib/api.ts` satisfies it. */
@@ -52,14 +65,39 @@ const taskIDSchema = {
additionalProperties: false,
} as const;
// A recovery tool's schema. `confirm` is required and must be true: a
// deliberate-action signal, not a security control (see the module header).
const recoverySchema = {
type: "object",
properties: {
task_id: {
type: "string",
description: "Task id, as shown on the dashboard's task pages.",
},
confirm: {
type: "boolean",
description:
"Must be true. State the intent explicitly rather than as a side effect of another action.",
},
},
required: ["task_id", "confirm"],
additionalProperties: false,
} as const;
/** One recovery action, published under its own name so the agent chooses by intent. */
function recoveryTool(client: DashboardApi, name: string, action: string, description: string): WebMcpTool {
return {
name,
description,
inputSchema: taskIDSchema,
inputSchema: recoverySchema,
annotations: { readOnlyHint: false, consequentialHint: true },
execute: async (input) => jsonEnvelope(await client.taskAction(taskID(input), action)),
execute: async (input) => {
const id = taskID(input);
if (input.confirm !== true) {
throw new Error(`${name}: confirm must be true; this action changes a task`);
}
return jsonEnvelope(await client.taskAction(id, action));
},
};
}
+14
View File
@@ -9,6 +9,20 @@
// shipping Chrome. WebMCP is an origin trial, so an absent modelContext is
// normal rather than an error: registration no-ops and the dashboard is
// unaffected.
//
// Three shapes in this API are JSON strings where an object is expected, and
// each failure looks like something else:
// - `getTools()` returns each tool's `inputSchema` as a JSON string; parse it
// before reading `.properties`, or the schema reads as empty.
// - `executeTool(tool, args)` takes its arguments as a JSON string, not an
// object (a plain object fails with "Failed to parse input arguments"), and
// its first argument must be the RegisteredTool object from `getTools()`,
// not a name (a name fails with a TypeError).
// - `executeTool` returns the tool's result as a JSON string that parses to
// `{content:[{type:"text",text}]}`, not as the envelope object itself.
//
// What the browser does not enforce, it should not appear to: see the
// annotation note in webmcp-tools.ts.
/** The annotation hints a WebMCP host reads. */
export interface WebMcpAnnotations {