Skip to content

MCP Apps sandbox: serve the proxy from a separate origin (SEP-1865 requires Host and Sandbox to differ) #6910

Open

Description

@yannj-fr

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

Refs: #6884, #6823, #6707. Spec: https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx

Activity

  1. copilotkit-outpost-bot commented on Sep 4, 2026

    @copilotkit-outpost-bot

    ⚠️ This is an AI-generated response. We've escalated this to our engineering team — someone will follow up in this thread shortly.

    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:

    • The alleged issue: buildSandboxHTML uses iframe.srcdoc with allow-scripts allow-same-origin, which one possibility is causes the sandboxed content to inherit the host's origin — potentially allowing access to host cookies/localStorage and DOM
    • The spec reference: SEP-1865 (2026-01-26/apps.mdx) explicitly requires Host and Sandbox to have different origins
    • The scope concern: The shared @copilotkit/mcp-apps-renderer package (from feat(mcp-apps-renderer): extract shared framework-agnostic MCP Apps host package (React pilot) #6884) would propagate this to all three frontends simultaneously
    • The proposed direction: Serve the proxy from a dedicated sandbox subdomain via iframe.src rather than srcdoc, keeping allow-scripts allow-same-origin (required by spec) but achieving genuine cross-origin isolation

    What the maintainers will need to assess:

    • Whether the srcdoc + allow-same-origin combination actually produces host-origin inheritance in the browsers/contexts CopilotKit targets
    • Whether the proposed separate-origin serving approach is feasible given the infrastructure requirements you noted (dedicated sandbox domain, local/dev fallback)
    • Compatibility implications for existing widgets that may rely on same-origin behavior

    The 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 👎

  2. BenTaylorDev commented on Sep 14, 2026

    @BenTaylorDev
    Contributor

    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:

    variant widget origin host cookies / DOM widget's own storage
    today, srcdoc + allow-same-origin the host origin full read and write works, in the host's jar
    src from a separate origin the sandbox origin SecurityError works
    no allow-same-origin null SecurityError SecurityError

    The spec requirements that go together are items 1 and 2 of the Sandbox proxy section:

    1. The Host and the Sandbox MUST have different origins.
    2. The Sandbox MUST have the following permissions: `allow-scripts`, `allow-same-origin`.
    

    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 sandboxOrigin option. This is the headline. When an app sets it, load the proxy with iframe.src from that origin instead of srcdoc, and validate event.origin on the host side. Ship proxy.html as 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: AppBridge does not validate origin for us. Its messageListener filters on event.source only, and send posts with targetOrigin "*". The check is ours to write.

    2. Make the unset default safe. An option nobody sets changes nothing, so with no sandboxOrigin configured 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:

    outer frame   the iframe attribute, set directly
                  mcp-apps-renderer session.ts:177 | vue :428 | angular :208
    
    inner frame   sent as the `sandbox` param of sendSandboxResourceReady(),
                  with the proxy template default lowered to match
                  mcp-apps-renderer sandbox.ts:32  | vue :31  | angular :644
    

    That inner path is already an ext-apps feature we left unused. Today we call bridge.sendSandboxResourceReady({ html }) with no sandbox, so the inner frame falls back to the template's allow-scripts allow-same-origin allow-forms. The upstream .d.ts example for this exact call passes sandbox: "allow-scripts", with no allow-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: true restores 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-origin without 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:

    storage APIs   localStorage sessionStorage indexedDB document.cookie
                   caches. navigator.storage serviceWorker document.domain   -> 0 hits
    indirect reach <script src=> <link href=> fetch( XMLHttpRequest
                   import( new Worker window[                                -> 0 hits
    repo-wide      every *.html tracked on origin/main                       -> 0 hits
    

    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

    • The relay forwards every message from the View to the Host unconditionally (sandbox.ts, the event.source===inner.contentWindow branch). Spec item 6 excludes methods that start with ui/notifications/sandbox-, so a widget can currently forge sandbox-proxy-ready. Low severity, worth fixing here.
    • The CSP is additive and permissive by default, against spec item 5. A srcdoc document inherits the parent policy, so proxy and View cannot hold different policies. Only the sandboxOrigin path can fix this, because a served document carries its own header.

    Tests

    • A negative test per frontend that the default sandbox attribute carries no allow-same-origin, on both frames.
    • A guard that the handshake completes with an opaque origin.
    • A test that allowSameOriginFallback restores the permission, so the escape hatch cannot rot.
    • The existing specs assert on iframe.srcdoc directly, for example mcp-apps-widget.spec.ts:160. The sandboxOrigin path turns those red and they need a variant per mode.
  3. JawsomeJason commented on Oct 13, 2026

    @JawsomeJason

    Confirming this is still present in @copilotkit/mcp-apps-renderer 1.79.0 (published 2026-10-12), using the documented setup (BuiltInAgent(...).use(new MCPAppsMiddleware({ mcpServers })) with the v2 React provider).

    • Both frames are still srcdoc with sandbox="allow-scripts allow-same-origin allow-forms": dist/session.mjs:326 and dist/sandbox.mjs:29.
    • sendSandboxResourceReady is still called without a sandbox param, so the inner frame takes the template default.
    • There is no sandboxOrigin option in 1.79.0 yet.

    Reproduction in a real app: from inside a ui:// view, top.document.title returned the host page's title, and a credentialed fetch to 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 sandboxOrigin option 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?

  4. removed their assignment
    on Oct 15, 2026
  5. Laptopmini commented on Oct 21, 2026

    @Laptopmini
    Contributor

    I picked this up and opened #7896 for steps 2 and 3 of the plan above, plus the relay fix.

    • MCP App widgets now get an opaque origin by default (allow-scripts allow-forms on both frames). The inner frame's flags go through the sandbox param of sendSandboxResourceReady.
    • allowSameOriginFallback restores the old flags. It's on mcpApps for the React and Vue CopilotKitProvider, and on provideMCPApps for Angular.
    • The proxy no longer relays 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 main in Chromium: a widget read top.document.title and the host's cookie. One more thing turned up. A widget that forges sandbox-proxy-ready makes 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.

  6. BenTaylorDev commented on Oct 28, 2026

    @BenTaylorDev
    Contributor

    @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) or provideMCPApps({ 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 sandboxOrigin option 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 to allowSameOriginFallback on mcpApps, and we'll settle how the per-resource CSP reaches the served proxy.html in that PR.

  7. Laptopmini commented on Oct 28, 2026

    @Laptopmini
    Contributor

    Thanks @BenTaylorDev, I took step 1 in #8055:

    • sandboxOrigin on McpAppSessionOptions, exposed as mcpApps.sandboxOrigin (React, Vue) and in provideMCPApps (Angular). It loads mcp-apps-sandbox-proxy.html, which now ships in @copilotkit/mcp-apps-renderer, via iframe.src, and the host checks event.origin and posts only to that origin.
    • CSP: the host sends the resource's csp in sandbox-resource-ready (the protocol already has the field). The proxy applies it to its own document before creating the widget frame, and the widget's srcdoc inherits 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions