Skip to content

Commit 154a49a

Browse files
authored
feat(dashboard): widget capabilities — net CSP, host tools, hardened shared sandbox (#111687)
* feat(boards): enforce widget capability grants * feat(ui): expose dashboard widget capabilities * test(dashboard): align rebased gateway contracts * refactor(dashboard): finish capability alignment * chore: internalize unused board sandbox exports * test(dashboard): bind grants to widget instances * fix(dashboard): close widget authority lifetime gaps * refactor(ui): preserve modular widget frame ownership * test(ui): preserve explicit MCP App lease refresh * test(ui): use shared dashboard sandbox server * fix(ui): settle widget requests on reconnect * fix(ui): retry transient widget document loads * refactor(dashboard): document WebRTC egress residual * fix(dashboard): clear landing checks
1 parent 444fd4b commit 154a49a

69 files changed

Lines changed: 5826 additions & 1235 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ enum class GatewayMethod(
459459
ConversationsList("conversations.list"),
460460
SessionDiscussionInfo("session.discussion.info"),
461461
SessionDiscussionOpen("session.discussion.open"),
462+
BoardPromptAuthorize("board.prompt.authorize"),
463+
BoardDataRead("board.data.read"),
464+
BoardAction("board.action"),
462465
}
463466

464467
enum class GatewayEvent(

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 125 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,14 @@ public struct BoardWidget: Codable, Sendable {
246246
public let revision: Int
247247
public let instanceid: String?
248248
public let declaredsummary: [String]?
249+
public let declared: BoardWidgetDeclared?
249250
public let frameurl: String?
251+
public let viewticket: String?
252+
public let viewticketttlms: Int?
253+
public let viewgeneration: String?
254+
public let sandboxurl: String?
255+
public let sandboxport: Int?
256+
public let sandboxorigin: String?
250257

251258
public init(
252259
name: String,
@@ -260,7 +267,14 @@ public struct BoardWidget: Codable, Sendable {
260267
revision: Int,
261268
instanceid: String? = nil,
262269
declaredsummary: [String]? = nil,
263-
frameurl: String? = nil)
270+
declared: BoardWidgetDeclared? = nil,
271+
frameurl: String? = nil,
272+
viewticket: String? = nil,
273+
viewticketttlms: Int? = nil,
274+
viewgeneration: String? = nil,
275+
sandboxurl: String? = nil,
276+
sandboxport: Int? = nil,
277+
sandboxorigin: String? = nil)
264278
{
265279
self.name = name
266280
self.tabid = tabid
@@ -273,7 +287,14 @@ public struct BoardWidget: Codable, Sendable {
273287
self.revision = revision
274288
self.instanceid = instanceid
275289
self.declaredsummary = declaredsummary
290+
self.declared = declared
276291
self.frameurl = frameurl
292+
self.viewticket = viewticket
293+
self.viewticketttlms = viewticketttlms
294+
self.viewgeneration = viewgeneration
295+
self.sandboxurl = sandboxurl
296+
self.sandboxport = sandboxport
297+
self.sandboxorigin = sandboxorigin
277298
}
278299

279300
private enum CodingKeys: String, CodingKey {
@@ -288,7 +309,32 @@ public struct BoardWidget: Codable, Sendable {
288309
case revision
289310
case instanceid = "instanceId"
290311
case declaredsummary = "declaredSummary"
312+
case declared
291313
case frameurl = "frameUrl"
314+
case viewticket = "viewTicket"
315+
case viewticketttlms = "viewTicketTtlMs"
316+
case viewgeneration = "viewGeneration"
317+
case sandboxurl = "sandboxUrl"
318+
case sandboxport = "sandboxPort"
319+
case sandboxorigin = "sandboxOrigin"
320+
}
321+
}
322+
323+
public struct BoardWidgetDeclared: Codable, Sendable {
324+
public let netorigins: [String]?
325+
public let tools: [String]?
326+
327+
public init(
328+
netorigins: [String]? = nil,
329+
tools: [String]? = nil)
330+
{
331+
self.netorigins = netorigins
332+
self.tools = tools
333+
}
334+
335+
private enum CodingKeys: String, CodingKey {
336+
case netorigins = "netOrigins"
337+
case tools
292338
}
293339
}
294340

@@ -620,15 +666,15 @@ public struct BoardWidgetPutParams: Codable, Sendable {
620666
public let title: String?
621667
public let content: BoardWidgetPutContent
622668
public let placement: [String: AnyCodable]?
623-
public let declared: [String: AnyCodable]?
669+
public let declared: BoardWidgetDeclared?
624670

625671
public init(
626672
sessionkey: String,
627673
name: String,
628674
title: String? = nil,
629675
content: BoardWidgetPutContent,
630676
placement: [String: AnyCodable]? = nil,
631-
declared: [String: AnyCodable]? = nil)
677+
declared: BoardWidgetDeclared? = nil)
632678
{
633679
self.sessionkey = sessionkey
634680
self.name = name
@@ -744,6 +790,82 @@ public struct BoardEventParams: Codable, Sendable {
744790
}
745791
}
746792

793+
public struct BoardTicketEventParams: Codable, Sendable {
794+
public let ticket: String
795+
public let payload: AnyCodable
796+
797+
public init(
798+
ticket: String,
799+
payload: AnyCodable)
800+
{
801+
self.ticket = ticket
802+
self.payload = payload
803+
}
804+
805+
private enum CodingKeys: String, CodingKey {
806+
case ticket
807+
case payload
808+
}
809+
}
810+
811+
public struct BoardPromptAuthorizeParams: Codable, Sendable {
812+
public let ticket: String
813+
814+
public init(
815+
ticket: String)
816+
{
817+
self.ticket = ticket
818+
}
819+
820+
private enum CodingKeys: String, CodingKey {
821+
case ticket
822+
}
823+
}
824+
825+
public struct BoardDataReadParams: Codable, Sendable {
826+
public let ticket: String
827+
public let bindingid: String
828+
public let params: [String: AnyCodable]?
829+
830+
public init(
831+
ticket: String,
832+
bindingid: String,
833+
params: [String: AnyCodable]? = nil)
834+
{
835+
self.ticket = ticket
836+
self.bindingid = bindingid
837+
self.params = params
838+
}
839+
840+
private enum CodingKeys: String, CodingKey {
841+
case ticket
842+
case bindingid = "bindingId"
843+
case params
844+
}
845+
}
846+
847+
public struct BoardActionParams: Codable, Sendable {
848+
public let ticket: String
849+
public let action: String
850+
public let jobid: String
851+
852+
public init(
853+
ticket: String,
854+
action: String,
855+
jobid: String)
856+
{
857+
self.ticket = ticket
858+
self.action = action
859+
self.jobid = jobid
860+
}
861+
862+
private enum CodingKeys: String, CodingKey {
863+
case ticket
864+
case action
865+
case jobid = "jobId"
866+
}
867+
}
868+
747869
public struct BoardChangedEvent: Codable, Sendable {
748870
public let sessionkey: String
749871
public let revision: Int

‎docs/docs_map.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10315,6 +10315,7 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
1031510315
- H2: Design system
1031610316
- H2: Use the tool
1031710317
- H2: Interactive widgets
10318+
- H2: Dashboard capabilities
1031810319
- H2: Security and storage
1031910320
- H2: Related
1032010321

@@ -10693,6 +10694,7 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
1069310694
- H2: Interaction tiers
1069410695
- H2: Widget model and hosting
1069510696
- H3: Widgets host content; MCP apps are one content kind
10697+
- H3: Modeled residual: WebRTC data channels
1069610698
- H3: Transcript display: one widget card
1069710699
- H3: Server-sourced widgets (pinned MCP apps)
1069810700
- H2: Layout: fluid grid

‎docs/tools/show-widget.md‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ read_when:
1515

1616
When the agent calls `show_widget`, OpenClaw core wraps `widget_code` in a minimal HTML document, stores it as a Canvas document, and returns a preview handle. The Control UI renders that handle as a sandboxed iframe directly under the tool call, while native apps use an isolated web view. Both restore the widget after history reload.
1717

18-
In Control UI sessions, a Canvas widget can also be pinned to the session dashboard. Set `pin: true` in the tool call, or use **Pin to dashboard** on an existing transcript widget. Pinning reuses the exact hosted document; it does not fetch widget HTML through the browser.
18+
In Control UI sessions, a Canvas widget can also be pinned to the session dashboard. Set `pin: true` in the tool call, or use **Pin to dashboard** on an existing transcript widget. Pinned HTML runs behind the same dedicated-origin, double-iframe sandbox host used by MCP Apps; the browser never resolves a widget data binding inside the untrusted frame.
1919

2020
For browser embedding, the wrapper document injects four small host bridges around the widget code:
2121

2222
- A size reporter posts the rendered content height to the embedding chat, which clamps it and fits the iframe (160 to 1200 pixels).
23-
- A prompt bridge defines a global `sendPrompt(text)` function that widget scripts can call to submit a follow-up message into the chat. The bridge creates a private message channel and offers one endpoint to the chat before any widget code runs; the chat adopts only that first offer. See [Interactive widgets](#interactive-widgets).
23+
- A host bridge defines the legacy `sendPrompt(text)` helper plus the structured `openclaw.prompt`, `openclaw.state`, `openclaw.data`, and `openclaw.cron` APIs. Inline chat prompts retain their private message channel; dashboard APIs use a view-ticket-bound request channel. See [Interactive widgets](#interactive-widgets) and [Dashboard capabilities](#dashboard-capabilities).
2424
- A theme bridge listens for the Control UI's current design tokens and applies them as CSS variables, on load and again on every theme change.
2525
- A snapshot bridge renders the current widget document as a PNG when the embedding chat requests an export.
2626

@@ -96,6 +96,7 @@ The core Canvas tool accepts these optional dashboard placement fields:
9696
- `tab`: destination tab slug.
9797
- `size`: one of `sm`, `md`, `lg`, `xl`, or `full`.
9898
- `after`: sibling widget name after which to place the widget.
99+
- `capabilities`: access requested by a pinned widget. `netOrigins` contains exact HTTPS origins; `tools` contains `prompt`, an allowlisted read binding, or an exact `cron.trigger:<jobId>` action.
99100

100101
The core result includes a Canvas preview handle, so the Control UI and supported native apps render the widget directly from the tool call and restore it after history reload. Pinned results also retain the board widget name so the Control UI does not offer a duplicate pin after transcript reload. Discord returns the stored widget and posted-message identifiers.
101102

@@ -120,14 +121,27 @@ Every prompt is validated on both sides of the frame boundary:
120121

121122
Accepted prompts appear in the transcript as regular user messages and start a normal agent turn in the session that owns the widget. There is no feedback channel into the widget: a dropped prompt fails silently, and the widget cannot read the agent's reply.
122123

124+
## Dashboard capabilities
125+
126+
Pinned widgets can use one ticket-bound host API after the operator reviews the declaration shown on the pending card:
127+
128+
- `openclaw.prompt.send(text)` requires transient user activation and posts a visible composer message. Declaring and receiving the `prompt` tool grant skips the extra per-click confirmation; validation, focus checks, and rate limits still apply.
129+
- `openclaw.state.emit(payload)` adds a session notice. Payloads are capped at 8 KiB, and identical client emissions within five seconds are coalesced.
130+
- `openclaw.data.read(bindingId, params?)` resolves only at the Gateway. Grantable bindings are `sessions.list`, `usage.status`, `usage.cost`, `cron.list`, `cron.status`, `agents.list`, and `health`.
131+
- `openclaw.cron.trigger(jobId)` runs an existing job now only when the exact `cron.trigger:<jobId>` capability was granted.
132+
133+
Network access is separate from host tools. Put exact HTTPS origins in `capabilities.netOrigins`; after approval, only those origins enter the widget's `connect-src`. Wildcards, credentials, paths, query strings, and undeclared origins remain blocked. A literal port is allowed only when it is part of the declared origin.
134+
123135
## Security and storage
124136

125-
Widget documents use restrictive Content Security Policies. Inline style and script are allowed, while external fetches and resource loads are blocked. Keep all markup, styles, scripts, and image data inside `widget_code`.
137+
Widget documents use restrictive Content Security Policies. Inline style and script are allowed, while external resource loads remain blocked. Inline transcript widgets cannot fetch the network. A pinned dashboard widget can fetch only exact HTTPS origins that the agent declared and the operator granted.
126138

127139
The Control UI iframe always omits `allow-same-origin`, even when the global embed mode is `trusted`, so widget scripts cannot read the parent application origin. Native clients use isolated, nonpersistent web views and block navigation away from the hosted widget. The core document host also serves widgets with a `Content-Security-Policy: sandbox allow-scripts` response header, so direct rendering still runs the widget in an opaque origin instead of an application origin. Only render widget code you are willing to execute in that isolated frame.
128140

129141
The iframe also follows [`gateway.controlUi.embedSandbox`](/web/control-ui#hosted-embeds). The default `scripts` tier supports interactive widgets while preserving origin isolation.
130142

143+
The accepted WebRTC data-channel egress residual is documented in [Dashboard Architecture](/web/dashboard-architecture#modeled-residual-webrtc-data-channels).
144+
131145
Canvas retains at most 32 widgets per session (or per agent when no session is available). Creating another widget removes the oldest document in that scope.
132146

133147
## Related

‎docs/web/dashboard-architecture.md‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,26 @@ Shared infrastructure underneath (this is where the simplification lands):
155155
one-tap **Allow**/**Reject**. Grants are per widget name; for `html` widgets
156156
they are byte-frozen (sha256), and changed bytes keep the grant only if the
157157
declaration shrank.
158-
- **Authoring shim.** The document wrapper injects
159-
`window.openclaw.sendPrompt/emitState/read/call` as the stable author API;
160-
whether the transport underneath is our channel or the AppBridge is an
161-
internal detail the widget author never sees. Size reporting and theme
162-
tokens ride the same bridge.
158+
- **Authoring shim.** The document wrapper injects `window.openclaw.prompt`,
159+
`window.openclaw.state`, `window.openclaw.data`, and `window.openclaw.cron`
160+
as the stable author API. Dashboard calls share one view-ticket-bound
161+
request channel; size reporting and theme tokens remain separate host
162+
notifications.
163+
164+
### Modeled residual: WebRTC data channels
165+
166+
The sandbox CSP emits the proposed `webrtc 'block'` directive, but
167+
[Chromium's current CSP directive set](https://chromium.googlesource.com/chromium/src/+/main/services/network/public/mojom/content_security_policy.mojom#95)
168+
does not implement it. Scriptable widgets can therefore use WebRTC data
169+
channels for egress in current Chromium. The same residual already ships for
170+
inline chat widgets and the MCP Apps host on `main`.
171+
172+
**Accepted tradeoff:** OpenClaw does not gate scriptable widgets on this
173+
residual. Widget content gains access to sensitive OpenClaw data only through
174+
an operator-granted, byte-frozen `data:read` capability, and the sandbox
175+
Permissions Policy blocks camera and microphone access. A DOM API guard is
176+
best-effort defense-in-depth, not a security boundary, and belongs in
177+
follow-up hardening.
163178

164179
### Transcript display: one widget card
165180

@@ -262,7 +277,15 @@ RPCs (core method table, typebox schemas in `gateway-protocol`):
262277
- `board.widget.put { sessionKey, name, html, manifest, placement }` —
263278
`operator.write` (agent tool path and pin path)
264279
- `board.widget.grant { sessionKey, name, decision }` — `operator.approvals`
265-
- `board.event { sessionKey, widget, payload }` — tier-1 state event ingest —
280+
- `board.event { ticket, payload }` — ticket-bound tier-1 state event ingest;
281+
the legacy trusted-host `{ sessionKey, widget, payload }` shape remains —
282+
`operator.write`
283+
- `board.prompt.authorize { ticket }` — returns whether a visible prompt send
284+
still needs per-click confirmation — `operator.read`
285+
- `board.data.read { ticket, bindingId, params? }` — gateway-side allowlisted
286+
read binding resolution — `operator.read`
287+
- `board.action { ticket, action: "cron.trigger", jobId }` — exact-grant
288+
automation dispatch through the existing cron run-now path —
266289
`operator.write`
267290

268291
Events (in `EVENT_SCOPE_GUARDS`, read scope):

‎packages/gateway-protocol/src/index.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ export * from "./schema/board.js";
2828
export * from "./migration-api.js";
2929
export type * from "./public-session-catalog.js";
3030
import {
31+
BoardActionParamsSchema,
32+
BoardDataReadParamsSchema,
3133
BoardEventParamsSchema,
3234
BoardGetParamsSchema,
35+
BoardPromptAuthorizeParamsSchema,
3336
BoardUpdateParamsSchema,
3437
BoardWidgetContentSchema,
3538
BoardWidgetAppViewParamsSchema,
@@ -684,6 +687,9 @@ export const validateBoardWidgetAppViewParams = lazyCompile(BoardWidgetAppViewPa
684687
export const validateBoardWidgetPutParams = lazyCompile(BoardWidgetPutParamsSchema);
685688
export const validateBoardWidgetGrantParams = lazyCompile(BoardWidgetGrantParamsSchema);
686689
export const validateBoardEventParams = lazyCompile(BoardEventParamsSchema);
690+
export const validateBoardPromptAuthorizeParams = lazyCompile(BoardPromptAuthorizeParamsSchema);
691+
export const validateBoardDataReadParams = lazyCompile(BoardDataReadParamsSchema);
692+
export const validateBoardActionParams = lazyCompile(BoardActionParamsSchema);
687693
export const validateWorktreesCreateParams = lazyCompile(WorktreesCreateParamsSchema);
688694
export const validateWorktreesRemoveParams = lazyCompile(WorktreesRemoveParamsSchema);
689695
export const validateWorktreesRestoreParams = lazyCompile(WorktreesRestoreParamsSchema);

‎packages/gateway-protocol/src/schema/board.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ describe("BoardSnapshotSchema", () => {
2525
grantState: "none",
2626
revision: 1,
2727
declaredSummary: ["Network access: https://example.com"],
28+
declared: { netOrigins: ["https://example.com"], tools: ["health"] },
2829
frameUrl: "/__openclaw__/board/agent%3Amain%3Amain/status/index.html?bt=ticket",
30+
viewTicket: "v1.ticket.signature",
31+
viewTicketTtlMs: 60_000,
32+
viewGeneration: "a".repeat(32),
33+
sandboxUrl: "/mcp-app-sandbox?csp=encoded",
34+
sandboxPort: 18790,
2935
},
3036
],
3137
};
@@ -42,6 +48,12 @@ describe("BoardSnapshotSchema", () => {
4248
widgets: [{ ...snapshot.widgets[0], declaredSummary: [42] }],
4349
}),
4450
).toBe(false);
51+
expect(
52+
Value.Check(BoardSnapshotSchema, {
53+
...snapshot,
54+
widgets: [{ ...snapshot.widgets[0], viewGeneration: "not-a-generation" }],
55+
}),
56+
).toBe(false);
4557
});
4658

4759
it("accepts declared grant summaries", () => {

0 commit comments

Comments
 (0)