Repository navigation
Description
Summary
The MCP Apps sandbox proxy is currently loaded via srcdoc, which makes the sandbox same-origin as the host. SEP-1865 requires the opposite: the Host and the Sandbox MUST have different origins.
What the spec requires
From the SEP-1865 security model (spec 2026-01-26/apps.mdx):
- "The Sandbox MUST have the following permissions:
allow-scripts,allow-same-origin." - "The Host and the Sandbox MUST have different origins."
- "If the Host is a web page, it MUST wrap the View and communicate with it through an intermediate Sandbox proxy."
allow-same-origin is correct and required. It is safe only when the Sandbox is a different origin from the host: then it gives the View its own stable, isolated origin (storage, cookies) while the different origin prevents it from touching the host. The double-iframe proxy relays JSON-RPC across that origin boundary.
Current behavior (pre-existing, from #6707)
buildSandboxHTML is loaded with iframe.srcdoc = ..., and the inner widget iframe is likewise inner.srcdoc = html, both with allow-scripts allow-same-origin. A srcdoc iframe with allow-same-origin inherits the embedder's (host) origin. So today the View runs with the host origin: it can reach host cookies/localStorage, and with allow-scripts + allow-same-origin it can escape into the host DOM. This is the "host-origin access" risk CodeRabbit flagged on #6884.
This is not introduced by the shared-package extraction (#6884) - buildSandboxHTML is verbatim from #6707 - but the extraction is the natural place to fix it once, for all three frontends.
Proposed fix
Serve the sandbox proxy from a separate origin (a dedicated sandbox domain/subdomain) via iframe.src = "https://<sandbox-origin>/..." instead of srcdoc, so the Host and Sandbox are genuinely cross-origin per the spec. Keep allow-scripts allow-same-origin on the sandbox (required), and keep the double-iframe proxy relay. This needs host infrastructure (a distinct origin to serve the proxy) and a fallback story for local/dev.
Scope
- Applies to all frontends once the shared
@copilotkit/mcp-apps-rendererpackage ownsbuildSandboxHTML(Extract a shared MCP Apps host package to remove per-framework duplication #6823 / feat(mcp-apps-renderer): extract shared framework-agnostic MCP Apps host package (React pilot) #6884). - Add compatibility tests for same-origin-relying widgets when the origin changes.
Refs: #6884, #6823, #6707. Spec: https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx
Activity
copilotkit-outpost-bot commentedon Sep 4, 2026
Thanks for the detailed write-up — this is a well-structured security analysis and I want to make sure the engineering team gets full visibility into it.
To be transparent about my role here: I'm the CopilotKit support assistant. I haven't read the source code of
buildSandboxHTML, reviewed PRs #6707, #6823, or #6884, or run any tests against the current sandbox behavior. I can't confirm or deny the described behavior from my position.What I can do is make sure this is clearly flagged for the maintainers who can actually verify it.
What you've described, for the team's review:
buildSandboxHTMLusesiframe.srcdocwithallow-scripts allow-same-origin, which one possibility is causes the sandboxed content to inherit the host's origin — potentially allowing access to host cookies/localStorageand DOM2026-01-26/apps.mdx) explicitly requires Host and Sandbox to have different origins@copilotkit/mcp-apps-rendererpackage (from feat(mcp-apps-renderer): extract shared framework-agnostic MCP Apps host package (React pilot) #6884) would propagate this to all three frontends simultaneouslyiframe.srcrather thansrcdoc, keepingallow-scripts allow-same-origin(required by spec) but achieving genuine cross-origin isolationWhat the maintainers will need to assess:
srcdoc+allow-same-origincombination actually produces host-origin inheritance in the browsers/contexts CopilotKit targetsThe CopilotKit team will need to verify the behavior, evaluate the spec alignment, and decide on the remediation path — that call is entirely theirs. If you want faster traction, the CopilotKit Discord is a good place to ping maintainers directly alongside this issue.
🤖 Generated by CopilotKit AI Support · Documentation
Was this helpful? React with 👍 or 👎
BenTaylorDev commentedon Sep 14, 2026
Maintainer call. Thanks for catching this, and for correcting your own first reply on #6884 within twenty minutes. The corrected diagnosis is right. I confirmed it in a real browser with a hostile widget payload before deciding:
srcdoc+allow-same-originsrcfrom a separate originSecurityErrorallow-same-originnullSecurityErrorSecurityErrorThe spec requirements that go together are items 1 and 2 of the Sandbox proxy section:
Item 1 is the security property and item 2 is a capability grant. We shipped the grant without the property, which is the top row of that table.
What we will do
1. Add a
sandboxOriginoption. This is the headline. When an app sets it, load the proxy withiframe.srcfrom that origin instead ofsrcdoc, and validateevent.originon the host side. Shipproxy.htmlas a static asset in the package so an app can serve it without copying a template string. That makes the spec-compliant path reachable for anyone who wants it, with no hosted dependency on us.Worth noting for step 1:
AppBridgedoes not validate origin for us. ItsmessageListenerfilters onevent.sourceonly, andsendposts withtargetOrigin"*". The check is ours to write.2. Make the unset default safe. An option nobody sets changes nothing, so with no
sandboxOriginconfigured the widget gets an opaque origin. The relay survives this. I confirmed the full handshake still completes.The host computes one sandbox string from the configuration and applies it in two places:
That inner path is already an ext-apps feature we left unused. Today we call
bridge.sendSandboxResourceReady({ html })with nosandbox, so the inner frame falls back to the template'sallow-scripts allow-same-origin allow-forms. The upstream.d.tsexample for this exact call passessandbox: "allow-scripts", with noallow-same-origin. Upstream's documented default is already the safe one, and it is also the clean way to plumb step 3 through to the inner frame.Until #6823 folds Vue and Angular into the shared package, both edits land three times.
3. Ship an escape hatch.
allowSameOriginFallback: truerestores today's behavior for a widget that genuinely needs client-side storage and has no separate origin available. Documented as unsafe without a distinct origin, because it is exactly the top row above.4. Document the deviation. With neither option set we depart from the letter of item 2 on purpose. Items 1 and 2 are a pair, and
allow-same-originwithout a distinct origin is the unsafe half on its own.Our own examples will take option 1 as the reference deployment, tracked in #7119.
Blast radius of the new default, measured
Zero of the ten in-tree widgets break. I searched for the mechanisms, not only the names:
All ten are self-contained inline HTML with no CDN script and no network call, so there is no path to storage, direct or borrowed from a library. Third-party widgets are the unknown, and the fallback flag in step 3 is the answer for them. If a widget needs persistence long term, the portable answer is a host-mediated storage channel over
postMessage, and that belongs upstream in ext-apps.Two smaller items in the same change
sandbox.ts, theevent.source===inner.contentWindowbranch). Spec item 6 excludes methods that start withui/notifications/sandbox-, so a widget can currently forgesandbox-proxy-ready. Low severity, worth fixing here.srcdocdocument inherits the parent policy, so proxy and View cannot hold different policies. Only thesandboxOriginpath can fix this, because a served document carries its own header.Tests
allow-same-origin, on both frames.allowSameOriginFallbackrestores the permission, so the escape hatch cannot rot.iframe.srcdocdirectly, for examplemcp-apps-widget.spec.ts:160. ThesandboxOriginpath turns those red and they need a variant per mode.JawsomeJason commentedon Oct 13, 2026
Confirming this is still present in
@copilotkit/mcp-apps-renderer1.79.0 (published 2026-10-12), using the documented setup (BuiltInAgent(...).use(new MCPAppsMiddleware({ mcpServers }))with the v2 React provider).srcdocwithsandbox="allow-scripts allow-same-origin allow-forms":dist/session.mjs:326anddist/sandbox.mjs:29.sendSandboxResourceReadyis still called without asandboxparam, so the inner frame takes the template default.sandboxOriginoption in 1.79.0 yet.Reproduction in a real app: from inside a
ui://view,top.document.titlereturned the host page's title, and a credentialedfetchto the host's own same-origin API returned the logged-in user. So a connected MCP server's view HTML can act as the signed-in user of the host app.Until the
sandboxOriginoption and the safe default from the plan above ship, our mitigation is to connect only first-party MCP servers whose views we write and review. Is there a target release for steps 1 and 2?Laptopmini commentedon Oct 21, 2026
I picked this up and opened #7896 for steps 2 and 3 of the plan above, plus the relay fix.
allow-scripts allow-formson both frames). The inner frame's flags go through thesandboxparam ofsendSandboxResourceReady.allowSameOriginFallbackrestores the old flags. It's onmcpAppsfor the React and VueCopilotKitProvider, and onprovideMCPAppsfor Angular.ui/notifications/sandbox-*from the widget.Since #7161 all three frontends share
bindMcpApp, so it's one change rather than three.I reproduced the original report on
mainin Chromium: a widget readtop.document.titleand the host's cookie. One more thing turned up. A widget that forgessandbox-proxy-readymakes the host resend its HTML, which reloads the widget, which forges again. It looped 2,126 times in 2.5 s. Both are fixed in the PR. The PR description has the before and after table.I left
sandboxOrigin(step 1) for a follow-up. The PR asks two questions about its API shape first.docs(mcp-apps): note CSRF and CORS limits of the opaque-origin sandbox
test(mcp-apps): document the sandbox test helpers
docs(mcp-apps): suggest single-file widget bundles to avoid CORS
docs(mcp-apps): note widgets can read responses from CORS-enabled APIs
fix(mcp-apps-renderer): give MCP App widgets an opaque origin by default
feat(mcp-apps): expose allowSameOriginFallback in React, Vue and Angular
docs(mcp-apps): document the opaque-origin sandbox and allowSameOrigi…
fix(mcp-apps)!: give MCP App widgets an opaque origin by default (Cop…
BenTaylorDev commentedon Oct 28, 2026
@JawsomeJason, the default is fixed as of v1.80.0 (#7896): MCP App widgets now run in an opaque origin, so a connected server's view can no longer read the host page's cookies, storage, DOM or same-origin API responses.
mcpApps={{ allowSameOriginFallback: true }}(React/Vue) orprovideMCPApps({ allowSameOriginFallback: true })(Angular) restores the old flags if a widget needs its own storage and you trust its server.Still open here: step 1, a
sandboxOriginoption that serves the proxy from a separate origin so widgets get both isolation and working storage. @Laptopmini, if you'd like to take the follow-up, it goes next toallowSameOriginFallbackonmcpApps, and we'll settle how the per-resource CSP reaches the servedproxy.htmlin that PR.Laptopmini commentedon Oct 28, 2026
Thanks @BenTaylorDev, I took step 1 in #8055:
sandboxOriginonMcpAppSessionOptions, exposed asmcpApps.sandboxOrigin(React, Vue) and inprovideMCPApps(Angular). It loadsmcp-apps-sandbox-proxy.html, which now ships in@copilotkit/mcp-apps-renderer, viaiframe.src, and the host checksevent.originand posts only to that origin.cspinsandbox-resource-ready(the protocol already has the field). The proxy applies it to its own document before creating the widget frame, and the widget'ssrcdocinherits it. That keeps the proxy a static file, unlike basic-host's?csp=→ header approach.The PR description has the cross-browser results and two questions on the option's shape.
docs(mcp-apps): recommend a separate domain for sandboxOrigin, not a …