OpenAI Revives Facebook Sandbox Architecture to Secure ChatGPT Apps

Why MCP and ChatGPT Apps Use Double Iframes — Frédéric Barthelet, Alpic — AI Engineer

AI Engineer

Standard browser sandboxing forces platforms to choose between credential theft and broken local storage, compelling AI hosts to adopt nested iframes that break apps contacting undeclared domains.

AI-assisted summary of Why MCP and ChatGPT Apps Use Double Iframes — Frédéric Barthelet, Alpic — original source. Check the original for full context.

Source published:

Key ideas

  • ChatGPT and Claude isolate third-party Model Context Protocol (MCP) apps using a nested double iframe architecture inherited from Facebook's original app marketplace. (3:31)
  • Direct single-iframe approaches fail due to browser security boundaries: standard `srcdoc` inherits the host's strict CSP, relaxing the CSP risks session token theft, and sandboxing with `allow-same-origin` causes a classic sandbox escape. (5:29)
  • The production pattern uses unique per-app subdomains on an untrusted proxy domain (such as `openaiusercontent.com`) to serve an identical, lightweight script loader that renders the app's HTML into an inner `srcdoc` frame with its own CSP meta tag. (12:03)
  • Alpic introduced Skybridge, an open-source development framework featuring a real-time CSP inspector to prevent common ChatGPT App Store submission rejections caused by undeclared outbound network domains. (15:55)

Detailed notes

## Background Published on YouTube by AI Engineer on June 15, 2026, this talk features Frédéric Barthelet, CTO and co-founder of Alpic. According to the description, Barthelet explains why inspecting ChatGPT during MCP app rendering reveals an iframe nested inside another iframe, systematically ruling out simpler sandboxing techniques and presenting Skybridge's CSP inspector tool.

## TL;DR Frédéric Barthelet investigates why AI hosts like ChatGPT and Claude rely on a nested double iframe architecture to execute third-party Model Context Protocol (MCP) view applications. Walking through simpler approaches—including raw `srcdoc`, relaxed parent CSPs, opaque sandboxing, and direct external sourcing—he illustrates how each either exposes sensitive host storage tokens or strips necessary client-side persistence APIs. To resolve this, platforms adopt a pattern pioneered by Facebook's app marketplace: an outer frame served from a dedicated, per-app subdomain hosts a static loader, which mounts an inner `srcdoc` iframe restricted by its own `<meta>` CSP tag. Because this architecture strictly blocks undeclared network calls, Barthelet demonstrates Skybridge, an open-source development tool with a live CSP inspector designed to prevent deployment errors and store rejections.

## Atmosphere & style The presentation carries the pragmatic, analytical tone of an engineering deep dive, feeling like an over-the-shoulder exploration through browser DevTools. Barthelet balances rigorous security logic with relatable developer nostalgia, comparing modern MCP security hurdles to historic CORS growing pains and early Facebook iframe architectures. The mood shifts smoothly from an architectural post-mortem into a hands-on live coding demonstration, wrapping up with an engaging, community-focused raffle for attendees.

## Bulletin - [03:31](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=211s) ChatGPT and Claude isolate third-party Model Context Protocol (MCP) apps using a nested double iframe architecture inherited from Facebook's original app marketplace. - [05:29](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=329s) Direct single-iframe approaches fail due to browser security boundaries: standard `srcdoc` inherits the host's strict CSP, relaxing the CSP risks session token theft, and sandboxing with `allow-same-origin` causes a classic sandbox escape. - [12:03](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=723s) The production pattern uses unique per-app subdomains on an untrusted proxy domain (such as `openaiusercontent.com`) to serve an identical, lightweight script loader that renders the app's HTML into an inner `srcdoc` frame with its own CSP meta tag. - [15:55](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=955s) Alpic introduced Skybridge, an open-source development framework featuring a real-time CSP inspector to prevent common ChatGPT App Store submission rejections caused by undeclared outbound network domains.

## Key takeaways - [00:15](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=15s) MCP apps and ChatGPT extensions represent a new commercial distribution surface combining conversational agent discovery with traditional app store listings. - [02:02](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=122s) MCP views are packaged HTML, CSS, and JavaScript bundles that are declared upfront during the initial `tools/list` handshake and rendered conditionally following tool executions. - [03:31](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=211s) Inspecting ChatGPT during MCP app execution reveals a nested double iframe pattern, rather than a single sandboxed frame. - [05:29](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=329s) Rendering an app via a top-level `srcdoc` iframe fails because it inherits ChatGPT's parent origin and strict CSP requiring cryptographic nonces on all scripts. - [05:29](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=329s) Relaxing ChatGPT's host CSP to run third-party scripts would grant untrusted apps read access to parent session tokens, cookies, and local storage. - [08:22](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=502s) Applying standard iframe sandboxing enforces an opaque null origin, which prevents apps from using origin-indexed storage like `localStorage`, `IndexedDB`, and cookies. - [08:22](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=502s) Adding `allow-same-origin` to a sandboxed iframe that shares the parent origin triggers a classic sandbox escape vulnerability back into the host's DOM and storage. - [08:22](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=502s) Directly loading third-party endpoints via an iframe `src` attribute is unworkable because the host would need an unbounded, continuously changing whitelist in its CSP `frame-src` directive. - [10:42](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=642s) Dynamically proxying and serving raw third-party HTML directly from a platform-owned domain introduces severe operational overhead and legal liability for arbitrary code. - [12:03](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=723s) The double iframe architecture solves origin sharing by hosting a static script loader on isolated subdomains (such as `app-id.openaiusercontent.com`) that injects view HTML into an inner `srcdoc` frame. - [12:03](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=723s) Using distinct subdomains for the outer frame prevents cross-app storage collisions, isolating `localStorage` and `IndexedDB` between different installed apps. - [12:03](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=723s) The nested iframe pattern mirrors the isolation technique Facebook originally engineered for its third-party app marketplace. - [14:00](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=840s) Every external domain an MCP app contacts (scripts, images, API calls) must be pre-declared in its manifest metadata to be written into the inner frame's CSP `<meta>` tag. - [14:00](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=840s) A key source of ChatGPT app store rejections was developer mode historically bypassing CSP enforcement, masking undeclared domain failures until production deployment. - [15:55](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=955s) Skybridge provides an open-source development suite with end-to-end typing, platform polyfills, and a live CSP inspector that diffs runtime network requests against declared manifest domains.

## Detailed walkthrough ### [00:15](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=15s) Introducing MCP Apps and the New UI Surface Area

Frédéric Barthelet introduces himself as the CTO and co-founder of Alpic, an MCP hosting platform, setting the stage for an architectural deep dive into how ChatGPT and Model Context Protocol (MCP) clients isolate third-party applications. Building on preceding talks by Liat and Ido, Barthelet emphasizes that MCP and ChatGPT apps represent an entirely new commercial surface area. This emerging distribution model combines two primary channels: store discoverability (such as the ChatGPT App Store or Claude connectors) and conversational discovery, where an agent dynamically pulls a relevant connector into an ongoing chat to provide extra context and trigger contextual actions.

The primary leap forward is moving conversational AI beyond plain text into interactive user interfaces. Rather than relying solely on generated conversational prose, conversational agents can now render rich client-side UI supplied directly by an MCP server or synthesized via generative UI. Barthelet traces the lineage of this capability from early community experiments with MCP UI (created by Liat and Ido), to OpenAI’s release of an App SDK in October of the prior year, to the standardized, multi-client specification known as the official MCP app extension.

> “That's a new surface area for your business to expose product and services with new acquisition channel that has two main criteria.” — Frédéric Barthelet

[02:02](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=122s) How Views and Tool Calls Work Under the Hood

To understand why isolation is so tricky, Barthelet walks through the lifecycle of UI rendering in MCP. In MCP terminology, these embedded visual components are called "views." A view is never launched in a vacuum; it is always rendered as the direct consequence of a tool call. When an MCP server registers its available tools, it can attach metadata specifying that a tool's output is best visualized through a dedicated view. If the host client supports the app extension, it intercepts the tool execution and uses the designated view to display the response.

Architecturally, views are standard web artifacts: packaged HTML documents bundling JavaScript and CSS. They are discovered ahead of time during the initial `tools/list` handshake when the conversational host first connects to the MCP server. Each tool that supports an interface advertises the exact assets required to render it, allowing the host either to pre-cache the bundle or fetch it on demand at runtime. When invoked, the conversational client mounts an inline frame into the chat feed and feeds dynamic tool results straight into the document context.

> “Views are simple HTML document. You can include JS and CSS inside. Nothing new under the sun here.” — Frédéric Barthelet

- **Lifecycle trigger:** Views are explicitly paired with specific tool calls via server metadata rather than spawned arbitrarily. - **Discovery timing:** UI resources are declared upfront during the initial `tools/list` exchange between the agent host and the MCP server. - **Dynamic data flow:** The host creates the frame and injects the live tool execution results into the rendering context.

[03:31](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=211s) The Double Iframe Surprise and ChatGPT's Baseline CSP

Curious about how OpenAI safely renders arbitrary untrusted web code directly inside conversational threads, Barthelet opened the browser developer tools on ChatGPT while an MCP app was active. Rather than finding a conventional single frame, he discovered a nested hierarchy: an iframe embedded inside an outer iframe. This unexpected "inception" pattern prompted him to investigate why standard web sandboxing techniques fell short and why client developers settled on this specific nesting architecture. While using ChatGPT as the running example, he notes that identical security constraints and implementations apply to Claude.

Before considering third-party code, one must look at ChatGPT's existing browser security baseline, governed by Content Security Policy (CSP) HTTP response headers. When loading ChatGPT, the server instructs the browser on what it may fetch, run, and embed. Two directives are particularly critical for third-party views: 1. `script-src`, which defines which scripts can execute in the browser context. 2. `frame-src`, which restricts which domains are permitted to serve iframes inside the parent page.

> “I was a bit surprised and I was met with not so much expectation about having a double iFrame, having an iFrame nested in inside another iFrame.” — Frédéric Barthelet

[05:29](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=329s) The Flaws of a Single Iframe with srcdoc and Relaxed CSP

The most intuitive implementation for rendering an MCP view is an `<iframe>` configured with the `srcdoc` attribute. Because the host already downloads the view's HTML bundle from the MCP server, passing the raw markup directly into `srcdoc` avoids making a redundant network request. However, Barthelet points out a critical limitation: an iframe populated via `srcdoc` inherits the parent document's origin by default, meaning it also inherits ChatGPT's strict CSP. ChatGPT protects its core application by enforcing a `script-src` policy that requires every script element to carry a unique, per-request cryptographic nonce generated ahead of time. Because arbitrary third-party application bundles lack this pre-generated nonce, their JavaScript is blocked completely by the browser engine.

As a thought experiment, Barthelet considers what happens if OpenAI were to relax ChatGPT's CSP to allow external, arbitrary scripts to run. While this would permit the app's JavaScript to execute, it introduces a severe security flaw: because the `srcdoc` frame shares the parent origin, any script running inside the embedded view shares full access to ChatGPT's origin-indexed storage. A malicious or compromised third-party app could read the user's ChatGPT session tokens, cookies, and `localStorage` keys, and silently transmit them to an external server.

> “I would not suggest doing that into production, just an experimental thought here.” — Frédéric Barthelet

```mermaid flowchart TD accTitle: Progression of single iframe failure modes accDescr: Diagram showing why direct srcdoc, relaxed CSP, sandbox, and allow-same-origin all fail to isolate third-party views.

subgraph DirectSrcDoc["Attempt 1: srcdoc Attribute"] A["Inject view HTML into iframe srcdoc"] --> B["Inherits parent ChatGPT origin & CSP"] B --> C["Blocked by script-src nonce requirement"] end

subgraph RelaxedCSP["Attempt 2: Relax Parent CSP"] D["Allow arbitrary script execution"] --> E["Same origin as ChatGPT parent DOM"] E --> F["App script can steal localStorage & cookies"] end

subgraph SandboxedFrame["Attempt 3 & 4: Sandboxing Trade-offs"] G["Add sandbox attribute"] --> H["Assigns opaque null origin"] H --> I["Breaks localStorage, IndexedDB & cookies"] I --> J["Add allow-same-origin to restore storage"] J --> K["Classic sandbox escape: restores full parent access"] end

C -.-> D F -.-> G ```

[08:22](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=502s) Sandboxing, Opaque Origins, and the Dead End of Direct src

To block origin sharing while still using inline document injection, the next logical step is adding the `sandbox` attribute to the iframe. Sandboxing forces the iframe into an opaque or "null" origin, severing its relationship with the parent DOM and preventing untrusted scripts from reading ChatGPT's cookies or session state. However, Barthelet explains that this creates an equally unacceptable trade-off: all standard web persistence mechanisms—such as `localStorage`, `indexedDB`, and cookies—are indexed strictly by origin. Under an opaque null origin, an app cannot persist any client-side state between interactions.

If a developer attempts to restore storage access by appending `allow-same-origin` to the sandbox attribute, the iframe is re-bound to the parent document's origin. This triggers the classic web sandbox escape vulnerability: the untrusted child frame regains full programmatic access to ChatGPT's DOM, authentication tokens, and storage, landing right back at square one.

Finally, Barthelet evaluates abandoning `srcdoc` in favor of pointing the iframe's `src` attribute directly to an external endpoint hosted by the app developer (for example, `https://myapp.com/view`). While this would assign the view its own distinct third-party origin and preserve local storage capabilities, it collapses on the host side. ChatGPT's CSP uses the `frame-src` directive to whitelist allowed frame origins. For an open marketplace, OpenAI would have to maintain and dynamically update an unbounded list of external developer domains in its production CSP header every time a new app or connector is published.

> “And the only way to actually provide an origin to a sandboxed iFrame is to put allow same origin, which is an additional attribute that brings back the exact same origin as the parent back into the iFrame and you're back to square one where you have an iFrame with exactly the right condition to escape its sandboxing and access parent DOM, access parent local storage, access parent cookies.” — Frédéric Barthelet

- **Opaque origin penalty:** Sandboxing an iframe with `sandbox` assigns a null origin, disabling `localStorage`, `indexedDB`, and cookie storage for the embedded view. - **The sandbox escape:** Combining `sandbox` with `allow-same-origin` on a document that shares the parent origin completely dismantles the security boundary. - **The `frame-src` bottleneck:** Relying on direct external endpoints via `src="https://..."` would force AI hosts to maintain an infinite, constantly changing whitelist of external domains in their core CSP headers.

[10:42](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=642s) The Proxy Domain Dilemma and Infrastructure Limits

Attempting to allow every arbitrary third-party domain at full scale is completely unworkable from a security perspective. Instead, a host platform can introduce a single proxy domain under its own control—such as `openaiusercontent.com`, which OpenAI uses specifically to expose untrusted user-generated content outside its primary web properties. By referencing this dedicated domain inside the host's Content Security Policy (CSP) `frame-src` directive, the browser will allow iframes pointing to it without compromising the primary application origin. Under this setup, a server hosted on the user-content domain fetches the raw HTML resources directly from the external Model Context Protocol (MCP) server and dynamically renders them, using a dynamic subdomain prefix as the routing key to distinguish between specific applications.

However, dynamically serving arbitrary third-party code through a platform-owned domain introduces severe operational and liability liabilities. The host platform effectively builds an infrastructure pipeline dedicated to hosting external user interfaces from every developer submitting to their store. As Frédéric Barthelet highlights, this places the host in a dangerous position: “Which is not a very good position to be into because once again, you will be responsible for code that you don't know what it's doing and you will be exposing it on your own domain.” Furthermore, smaller hosts outside of OpenAI or Anthropic rarely possess the engineering and infrastructure resources required to orchestrate this level of complex, dynamic server-side content distribution.

- `openaiusercontent.com` serves as OpenAI’s designated secondary domain to display untrusted content safely off the primary `chatgpt.com` origin. - Routing keys embedded in subdomains (for example, `app-id.openaiusercontent.com`) direct incoming traffic to the appropriate MCP application assets. - Dynamically proxying and hosting external HTML forces the platform owner to accept direct liability for rendering unknown, untrusted code.

---

[12:03](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=723s) The Double Iframe Architecture and Facebook's Legacy

To resolve the hosting dilemma, hosts turn to the double iframe pattern. Instead of generating distinct HTML files dynamically on the server for each app, the outer iframe serves a single, universal, and lightweight script loader to every client. This script retrieves the target application's resources and instantiates an inner nested iframe populated via the `srcdoc` attribute. Because the outer iframe resides on an external sandbox domain separate from ChatGPT, the inner `srcdoc` frame inherits the sandbox domain's origin rather than the parent ChatGPT application, eliminating the sandbox escape and data-leak vulnerabilities inherent in top-level `srcdoc` usage.

To prevent cross-application interference, the outer loader script is served across unique per-app subdomains. While every subdomain serves the exact same static JavaScript loader, the distinct origins ensure that browser APIs requiring origin indexing—such as `localStorage`, `IndexedDB`, and cookies—cannot collide or be accessed across applications. For instance, application `ABC123` cannot inspect the stored credentials or cache of application `ABC456`. Content Security Policies are then enforced inside the view by injecting an appropriate `<meta http-equiv="Content-Security-Policy">` tag into the inner frame based on the app's MCP specification metadata. Barthelet notes that this architecture is not novel, but rather a battle-tested pattern borrowed from early web application platforms: “This is the actual solution that I implemented into production. And it's not a new solution. It's been around for a long time and actually the first time this solution was implemented was back in Facebook days when they released their app marketplace, which is exactly the same problem that you have to run and render third-party UI inside the context of your own application.”

```mermaid flowchart TD accTitle: Double Iframe Isolation Architecture accDescr: Diagram showing ChatGPT embedding an outer iframe on a dedicated subdomain, which in turn embeds an inner srcdoc iframe with its own CSP meta tag.

subgraph ParentHost ["Host Application (chatgpt.com)"] HostApp["ChatGPT Main DOM"] end

subgraph OuterSandbox ["Outer Iframe Sandbox"] OuterFrame["app-id.openaiusercontent.com<br/>(Lightweight Static Script Loader)"] end

subgraph InnerContent ["Inner Iframe Sandbox"] InnerFrame["Nested srcdoc Iframe<br/>(MCP App HTML + UI)"] CSPMeta["Meta Tag CSP<br/>(Enforces Declared Domains)"] end

HostApp -->|"Embeds via frame-src"| OuterFrame OuterFrame -->|"Loads static script & renders"| InnerFrame InnerFrame --- CSPMeta ```

- **Outer Iframe:** Serves an identical, static JavaScript loader across isolated subdomains, drastically minimizing backend hosting infrastructure. - **Origin Indexing Isolation:** Distinct subdomains prevent separate apps from reading each other's `localStorage`, session storage, or cookie jars. - **Inner Iframe:** Receives app markup via `srcdoc` and applies client-side CSP restrictions using HTML `<meta>` tags. - **Historical Precedent:** Facebook popularized this exact nested iframe sandboxing structure when launching its original third-party App Marketplace.

---

[14:00](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=840s) CSP Declarations, Metadata, and Developer Pain

For application developers building on top of the MCP app specification, the double iframe architecture imposes strict configuration requirements. Because the inner iframe renders under an explicit CSP `<meta>` tag, any external domain the application communicates with or loads assets from must be declared ahead of time inside the application's MCP metadata. When the host environment constructs the nested iframe, it rewrites these metadata declarations into the appropriate CSP policy directives. If an app makes an outbound network call to an external API to retrieve data, that endpoint must be explicitly declared in the `connect-src` array; similarly, third-party libraries, tracking pixels, or visual assets require explicit entries under `script-src` and `img-src`.

Dealing with rigid browser security directives evoked painful memories for Barthelet, who recalled his early days as a software engineer: “As a new developer in the space, I was experiencing a trouble getting cross-origin resource security right calls. I had trouble getting it right. CSP reminded me of those ugly day of not getting right the first time with calls.” Historically, developer ergonomics around MCP testing were severely flawed. In ChatGPT's developer mode, CSP enforcement was historically stripped out entirely during local testing. As a result, developers would successfully test an application locally, only to discover upon deploying to production or submitting to the app store that their views failed to render and their network requests were blocked due to undeclared CSP origins.

- Developers must declare all external endpoints across directives like `connect-src`, `script-src`, `img-src`, and `frame-src` within their MCP app manifest. - Failing to declare a domain causes the browser's CSP engine inside the inner iframe to reject network requests and script executions immediately. - Previous iterations of ChatGPT's developer mode completely bypassed CSP rules, creating a false sense of security that led to immediate breakages in production environments.

---

[15:55](https://www.youtube.com/watch?v=c-2eEv2ou7Y&t=955s) Skybridge and the Live CSP Inspector Demo

To eliminate the friction of CSP mismatches and platform inconsistencies, Alpic built Skybridge, an open-source development framework designed as a superset of the official MCP app SDKs. Skybridge provides end-to-end type safety between MCP backend servers and frontend widgets, bundles polyfills for host-specific platform quirks across Claude and ChatGPT, and introduces dedicated local inspection tooling. Barthelet switched to his screen to demonstrate Skybridge’s local development environment, running a starter Magic 8-Ball sample application featuring an MCP tool that selects from 25 predefined answers and a reactive view component that renders the question and response.

``` +------------------------------------------------------------------+ | Skybridge CSP Inspector | | | | [Status: MISMATCH DETECTED] | | | | Declared Domains (Metadata): | | - None | | | | Live Network Activity: | | - [X] https://api.iplocation.net/ <-- MISSING IN METADATA! | | | | Action: Add "api.iplocation.net" to connect-src in mcp.json | +------------------------------------------------------------------+ ```

Opening the Skybridge dev tool in the browser, Barthelet highlighted its built-in CSP Inspector. The tool monitors all network requests initiated by the active view in real time and diffs them against the domains declared in the app’s metadata. While the initial Magic 8-Ball view showed all green checks, Barthelet edited the source code live to fetch the user’s IP location from an external API. The inspector immediately flagged the undeclared domain in red as a missing CSP entry. After he added the API domain to the metadata configuration file and refreshed, the status returned to green. Barthelet explained the practical necessity of this tool: “So, neat little tool. There are a lot of other features that are packed inside Skybridge, but that's one of them that we made sure to be available to builders because we've seen a lot of rejection coming from ChatGPT app store submission because of missing CSP and app not working in production because of missing CSP domains.” He concluded his presentation by inviting the audience to scan on-screen QR codes for his slide deck and GitHub repository, holding an impromptu raffle of ski goggles for attendees who starred the Skybridge repo.

- **Skybridge Framework:** Open-source tooling from Alpic delivering TypeScript safety, host polyfills (Claude/ChatGPT), and local emulation. - **Magic 8-Ball Demo:** A starter MCP application demonstrating split execution between an answer-generation tool (25 possible outcomes) and an interactive canvas view. - **CSP Inspector:** Intercepts real-time runtime network calls and flags any discrepancies against declared MCP manifest domains before store submission. - **Community Incentive:** A live giveaway of ski goggles was held for audience members starring the Skybridge repository at the close of the session.

## Mentioned Frédéric Barthelet, Alpic, Skybridge, ChatGPT, OpenAI, Model Context Protocol (MCP), Anthropic, Claude, Facebook, Liat, Ido, openaiusercontent.com

## Video description Inspect ChatGPT's DOM while an MCP app is rendering and you find an iframe nested inside another iframe. Frédéric Barthelet traces why each simpler approach fails: `srcdoc` shares the parent origin so ChatGPT's CSP blocks all third party scripts; relaxing that CSP lets any app read ChatGPT's localStorage and cookies; adding `sandbox` removes origin indexed storage; adding `allow-same-origin` to restore it is the classic sandbox escape. The double iframe is what remains after ruling all of that out.

The outer iframe serves one lightweight script from a controlled subdomain (different subdomain per app to prevent cross app storage collisions), which loads the actual app HTML via `srcdoc` into the inner frame — the same pattern Facebook first shipped for their app marketplace. The practical implication: every external domain your view touches must be declared in your MCP app metadata or the submission gets rejected. Barthelet demos Skybridge's CSP inspector, which diffs declared domains against actual network calls live in dev.

Speaker info: - https://x.com/bartheletf - https://www.linkedin.com/in/frederic-barthelet/ - https://github.com/fredericbarthelet

---

Watch along with the corrected transcript, summary, timestamps and resources on this talk's official AIE page: https://ai.engineer/talks/c-2eEv2ou7Y-why-mcp-and-chatgpt-apps-use-double-iframes-frederic-barthelet-alpic

Join our upcoming AI Engineer conferences (see https://ai.engineer landing page):

- AIEi Shanghai, November 5–6 — the first for meeting top Chinese labs and engineers - AIE CODE in SF, November 10–12 — the top AI Coding conference returns - AIEi Sydney, December 7–8 — the first AIEi run alongside NeurIPS 2026 in Sydney

---

[Source](https://www.youtube.com/watch?v=c-2eEv2ou7Y)

Reading summary

To safely execute untrusted third-party user interfaces inside conversational agents without compromising core application data, platforms like ChatGPT and Claude rely on a nested double iframe architecture. Frédéric Barthelet explains that this pattern balances strict Content Security Policies, client-side storage isolation, and manageable hosting infrastructure. Why Single Iframes Fail Security Sandboxing (3:31) Model Context Protocol (MCP) applications allow conversational agents to move beyond text by rendering client-side HTML, CSS, and JavaScript views triggered by tool calls. However, embedding this untrusted code directly into a host application like ChatGPT through a single iframe creates severe browser security conflicts. Injecting markup via the srcdoc attribute causes the child frame to inherit the host's origin and strict Content Security Policy (CSP). Because ChatGPT requires scripts to carry a pre-generated cryptographic nonce under its script-src directive, third-party code fails to execute. Relaxing the parent CSP is unacceptable because scripts sharing the parent origin could read sensitive session tokens, cookies, and local storage. The Dead End of Direct Sandboxing and External Domains (8:22) Standard browser sandboxing techniques fail to resolve the problem cleanly. Adding a sandbox attribute isolates the document by assigning it an opaque null origin, preventing parent data theft; however, this disables essential client-side persistence APIs like localStorage, indexedDB, and cookies, which are strictly origin-indexed. Attempting to restore storage access by adding allow-same-origin introduces a classic sandbox escape vulnerability, re-exposing the parent DOM. Pointing an iframe directly to a developer-hosted external URL via the src attribute preserves origin isolation, but breaks host CSP constraints: the host would have to maintain an unbounded, constantly shifting whitelist of developer domains inside its primary frame-src directive. The Double Iframe Solution and Subdomain Isolation (12:03) Platforms resolve this deadlock by adopting a double iframe pattern originally popularized by Facebook's third-party app marketplace. The host embeds an outer iframe hosted on an isolated, platform-controlled secondary domain, such as openaiusercontent.com, which is safely whitelisted in the host's frame-src policy. Instead of dynamically serving custom backend HTML per app, the outer frame loads a single, universal static JavaScript loader across unique subdomains (such as app-id.openaiusercontent.com). This script dynamically instantiates an inner nested iframe populated via srcdoc. Metadata Declarations and Developer Tooling (14:00) Because the inner iframe inherits the outer frame's unique sandbox subdomain rather than chatgpt.com, client storage remains isolated across different applications without leaking host credentials. The inner frame then enforces security boundaries using injected HTML meta tags that translate the developer's MCP manifest declarations into explicit CSP directives, including connect-src and script-src. Any undeclared external API call or asset is blocked by the browser. To prevent store submission rejections caused by missing CSP declarations—which were historically obscured because ChatGPT's local developer mode stripped out CSP enforcement—Alpic developed Skybridge, an open-source development tool with a live CSP inspector that diffs runtime network calls against manifest files. The nested iframe architecture successfully isolates untrusted UI while avoiding unmanageable proxy infrastructure, but it shifts the configuration burden to application developers who must strictly declare all outbound endpoints. Missing CSP declarations remain a primary point of failure during production deployment and marketplace review.

Original transcript

[0:07] [music] [0:15] >> Hi everyone. [0:16] My name is Fred. I'm the CTO and [0:18] co-founder of Alpic, the MCP hosting [0:21] company. [0:22] And today I would like to share with you [0:23] an adventure deep diving into the double [0:26] iFrame mechanism that we have on ChatGPT [0:28] and MCP app and what it matters when we [0:30] build apps. [0:32] First thing first, if you haven't had [0:34] the chance to listen to either Ido and [0:38] Leat talks just before about MCP apps, a [0:41] quick sum up of what those MCP and [0:44] ChatGPT apps are. [0:46] That's a new surface area for your [0:48] business to expose product and services [0:50] with new acquisition channel [0:52] that has two main criteria. First one [0:54] being discoverability, so you will have [0:56] ecosystems of connectors and apps [0:59] available in a consumer generalistic [1:02] agent like ChatGPT and Claude. So [1:04] ChatGPT app store and Claude connectors. [1:06] Those apps [1:08] browsable inside the store, but they are [1:10] also discoverable in chat. So if you're [1:13] having a conversation that's relevant [1:14] for an app to be brought into to add [1:16] additional context and feature some nice [1:19] additional actions, they will be brought [1:21] into the conversation. [1:23] And the second part, which is the [1:24] biggest part and what we will be [1:26] focusing on in this talk, which is the [1:28] addition of interactive UI inside those [1:30] conversational agents where you used to [1:33] add text only. Apps add a new layer of [1:36] UI that could be provided by the MCP [1:38] server, [1:39] but could be generated generative UI as [1:42] well. [1:43] They were first thought of using MCP UI [1:46] that was developed by Leat and Ido just [1:48] before, then released by Open AI with an [1:52] app SDK back in October last year and [1:54] standardized across multiple clients on [1:57] the first official extension of MCP [1:59] called the app extension. [2:02] How does it work under the hood? If we [2:03] take a little bit [2:05] closer look at [2:07] how this UI is brought into the [2:08] conversation, [2:10] those are brought using views. Views are [2:13] the name that we use for those small [2:15] snippet of UI that appears inside the [2:16] conversation. [2:18] Views are always rendered as a result of [2:21] a tool call. So if your server exposed [2:23] multiple tool to be used, you can [2:25] actually add metadata on some of them to [2:27] say this tool is best used when [2:30] results will be displayed using a [2:32] specific UI. And if the host supports [2:34] MCP apps, it will use [2:36] the relevant view corresponding to this [2:39] tool call to display the results. [2:41] Views are simple HTML document. You can [2:44] include JS and CSS inside. Nothing new [2:46] under the sun here. It's just a way to [2:48] package those small snippets of [2:50] application and [2:52] they are discoverable ahead of time [2:54] because all views are described on the [2:57] tool list calls that happens at the [2:59] beginning of the conversation between [3:00] the host and your MCP server or MCP app. [3:04] So each tools that supports UI will [3:07] advertise the resource that's needed to [3:09] display the UI. It can be cached ahead [3:11] of time or it can be served and [3:14] downloaded and served right away when [3:15] the tool call that needs UI to be [3:17] rendered is made. [3:19] The conversational agent on the host [3:22] will create this new iFrame where the [3:24] view will be displayed and it will [3:26] inject the tool results inside so that [3:28] you have dynamic content rendered to the [3:30] user. [3:31] If you take a closer look at what is [3:34] inside the [3:37] DOM of the host when you take a [3:40] I was a bit curious and I wanted to know [3:41] how it was working or how ChatGPT was [3:43] actually rendering third-party UI inside [3:47] the conversation. [3:48] I was a bit surprised and I was met with [3:51] not so much expectation about having a [3:53] double iFrame, having an iFrame nested [3:56] in inside another iFrame. And this gave [3:59] me the idea for this talk. I want to [4:02] bring you today with me deep diving into [4:04] why the decision was made to do this [4:06] kind of inception nesting of iFrames and [4:09] what are the benefits, what was it put [4:10] in place and what are the implications [4:12] when you build apps, what should be [4:13] paying attention to and how to make sure [4:16] that your experience is very nice. [4:18] Before we go into that, let's take a [4:20] close look at what ChatGPT was before [4:23] MCP app were implemented. We'll be using [4:25] ChatGPT as the example throughout this [4:27] deep dive, but the exact same happened [4:29] on Claude AI if you want to take another [4:31] look by yourself. The initial thing to [4:34] take a look at that is very important is [4:36] something called content security [4:38] policy. Those are directives returned by [4:41] server as response header to document [4:45] call. So when you load ChatGPT inside [4:46] your browser, ChatGPT will respond with [4:48] a document plus security policy [4:51] directive on what the browser should be [4:53] allowed to load and execute and what it [4:55] shouldn't be allowed to load and [4:56] execute. You've got multiple directives [4:59] included inside content security policy. [5:01] Some about which scripts you can run, [5:03] which CSS style sheet you can download, [5:05] which image you can download, which API [5:08] you can connect to and ask question to. [5:11] I will not go into the details, but two [5:12] are very important to remember here. [5:14] Frame SRC, which basically is a [5:16] directive to allow [5:18] specific website to render iFrame inside [5:20] the document and script SRC, which [5:22] basically allow specific sites [5:25] script to be run inside the browser. [5:29] To be able to run [5:31] external UI inside ChatGPT, we will use [5:33] a dedicated HTML element that has been [5:36] made specifically for this purpose, [5:38] which is the inline frame element or [5:40] iFrame [5:42] that is made to basically spawn up [5:44] nested browsing context inside your [5:47] browser window. So those small pieces of [5:49] views will be rendered as almost [5:51] separately completely isolated browsing [5:54] context. They are very convenient and [5:56] they have two ways to be used. First one [5:59] is to provide a source for the iFrame [6:01] that you want to render. So basically a [6:02] URL of another page to be loaded by your [6:04] browser and executed locally and [6:06] rendered inside the space it's made of [6:08] it's made for. And the source doc, which [6:11] is another attribute which allows you to [6:14] push inside the iFrame content that you [6:17] want to render as is without having the [6:19] browser to load another content. [6:22] So if you want to build this marketplace [6:23] of app and have third-party UI rendered [6:26] inside ChatGPT, why not use straight [6:27] away source doc as the attribute for [6:32] as the attribute for uh [6:34] for injecting context into. And I'm [6:36] realizing now that it's a little bit [6:38] small, but I think I can zoom in a bit. [6:41] No, I cannot. Okay, sorry about that. [6:43] You'll have to trust me about what is [6:44] written inside here. So [6:47] I will just put inside an iFrame [6:49] injecting context into the iFrame. [6:51] Context being the content being [6:53] basically the resource that is being [6:55] exposed by the MCP server. So pure HTML [6:57] loading inside. If I do that, uh [7:01] it's not going to work mostly because [7:04] when you load up an iFrame with source [7:06] doc attribute [7:08] specified, the iFrame that you are [7:11] spawning up is sharing the same origin [7:13] and sharing the same therefore CSP as [7:16] the host that is responsible for [7:18] rendering it. So [7:20] any script that would be part of your [7:21] application that would be completely [7:24] blocked by existing ChatGPT CSP on [7:27] script SRC directive, which basically [7:29] require every script in ChatGPT to be [7:31] signed with a specific nonce produced [7:33] ahead of time at each request, which is [7:36] a cool security feature to put in, but [7:38] it prevents any app to be able to [7:40] execute JS. [7:42] So in order to do that, [7:44] what if we relax a little bit the [7:45] content security policy of ChatGPT and [7:47] make it [7:48] so that it can execute any line of code? [7:51] I would not suggest doing that into [7:52] production, just an experimental thought [7:53] here. [7:55] But if you do that, you are faced a new [7:57] problem. [7:58] Basically, you are sharing same origin [8:00] as your parent DOM. So the loaded iFrame [8:03] scripts would be able to access local [8:06] storage or cookies that are indexed by [8:08] origin. So you would be able as an app [8:11] to [8:12] for example get the existing local [8:14] storage of ChatGPT and send it to your [8:16] back-end server, which if you are Open [8:19] AI, you would not want people to be able [8:21] to do. [8:22] So let's roll back, put back the CSP as [8:24] it was before and instead [8:27] sandbox the iFrame. Sandbox is another [8:30] attribute that you can use on iFrames [8:32] allowing iFrames to be rendered in what [8:34] we call the no pack origin. It would [8:37] mean that basically the iFrame will not [8:39] share anymore the parent origin. It [8:41] would be something equivalent to null [8:43] making sure that they don't share the [8:46] same origin and won't have the same [8:47] problem of script being able to access [8:50] the parent DOM. [8:52] However, doing so, [8:54] you lack any capabilities that are [8:57] dependent on origin indexing. Because [9:00] all content, all scripts that are [9:02] rendered inside your iFrame will now be [9:04] pointing towards a null origin. You [9:06] cannot use local storage. You cannot use [9:08] local index DB. You cannot use cookies [9:10] because those are indexed by origin. And [9:12] the only way to actually provide an [9:14] origin to a sandboxed iFrame is to put [9:17] allow same origin, which is an [9:18] additional attribute that [9:20] brings back the exact same origin as the [9:22] parent back into the iFrame and you're [9:24] back to square one where you have an [9:26] iFrame with exactly the right condition [9:28] to escape its sandboxing and access [9:31] parent DOM, access parent local storage, [9:33] access parent cookies. [9:36] Okay, so [9:37] iFrame source doc is not the way to go [9:40] forward. Let's move on to the next best [9:42] solution that we have using the source [9:44] attribute. [9:45] Source attribute basically allows me to [9:47] reference an [9:49] an endpoint that will be the content [9:51] loaded by the browser inside this [9:53] iFrame. [9:54] I'm a developer of the ChatGPT app and [9:57] MCP app. [9:58] Why not expose my view, my small HTML [10:02] application [10:03] as a normal endpoint like on the view [10:06] endpoint for example of my own server? [10:09] That would be a nice way to do it. [10:11] However, it would require [10:14] open AI to modify [10:16] the another CSP directive, which is [10:18] basically the frame source directive [10:21] listing all domains that are allowed to [10:23] actually render iframe on chat GPT to [10:25] include an infinite list of all the MCP [10:28] application that will be developed by [10:30] various companies and brought into the [10:32] store. So, every time a new app would [10:34] come out, [10:36] chat GPT would have to update CSP to [10:37] include the new domain so that the frame [10:39] can be rendered on the specific domain. [10:42] This is not doable full scale. So, what [10:45] we can do instead is [10:48] provide kind of a proxy [10:50] controlled domain, single one that will [10:53] be owned by chat GPT in that case. For [10:56] example, open AI open AI user [10:58] content.com. That's an actual domain [11:00] that they're using for user content that [11:02] they want to expose on their own domain. [11:05] And use this domain as a reference [11:07] inside the frame source to make sure [11:08] that the directive does not block [11:09] rendering any iframes that are loaded on [11:11] there. [11:12] And you need to provide a server on the [11:14] open AI user content that's able to [11:16] download the resource content from the [11:18] MCP server, the HTML, and expose it so [11:21] that it can be rendered for example on [11:23] any subdomain and use the first part of [11:25] the subdomain as the routing key to the [11:27] right application. [11:29] Doing so, you effectively needs to put [11:32] in motion an infrastructure where your [11:34] domain [11:35] hosts [11:36] external third-party UI from all apps [11:39] that will be submitted on your store. [11:41] Which is not a very good position to be [11:43] into because once again, you will be [11:45] responsible for code that you don't know [11:47] what it's doing and you will be exposing [11:49] it on your own domain. [11:51] In addition to that, if you're not open [11:53] AI or if you're not Anthropic, you might [11:55] not have the resource as a host to put [11:57] in place the infrastructure required to [12:00] serve this kind of dynamic serving of [12:02] content. [12:03] So, what you can do instead [12:05] is [12:07] go through the double iframe mechanism. [12:10] And what you will do with that is [12:11] basically load the same script for [12:13] everybody, which will be a simple script [12:15] responsible to recover the resources and [12:17] initiate an iframe with the source doc [12:19] attribute. So, we put the content [12:21] inside, but this iframe will not be [12:24] served at top level because it shares [12:25] the same origin and it has the escaping [12:27] problem we are mentioning before. It [12:29] will be served inside an iframe with [12:31] dedicated domain that is different from [12:33] chat GPT to make sure the isolation stay [12:35] there. [12:36] You won't don't want to stop there. [12:37] Actually, you want to [12:39] put subdomains for this exact script [12:42] loader. [12:43] It will be the exact same content that [12:45] will be served every time, but you want [12:46] to put it on various subdomains so that [12:48] if your app uses any [12:51] APIs that requires origin indexing like [12:53] local storage or cookie, you don't have [12:55] collision in between your app. So, you [12:57] want app ABC123 not to be able to access [12:59] local storage from app ABC456 for [13:02] example. [13:03] The infrastructure for that is much [13:06] less intensive because you're serving [13:08] the exact same script content of the [13:10] first iframe for every subdomain that is [13:13] exist on this specific endpoint. [13:16] Last but not least, [13:17] you want to be able to provide the same [13:19] kind of content security policy [13:20] definition to the app itself so that it [13:23] can prevent execution of any such script [13:25] or rendering of iframe [13:28] directly inside the view. [13:30] There is a way to provide this into the [13:32] MCP spec and the way you will render it [13:34] is using a specific meta tag inside the [13:37] first iframe. [13:39] This is the actual solution that I [13:40] implemented into production. [13:42] And it's not a new solution. It's been [13:46] around for a long time and actually the [13:47] first time this solution was implemented [13:49] was back in Facebook days when they [13:50] released their app marketplace, which is [13:52] exactly the same problem that you have [13:54] to run and render third-party UI inside [13:57] the context of your own application. [14:00] What's important for you as an app [14:03] developer is to make sure what are the [14:05] specs available for you to be able to [14:07] control the behavior that results from [14:09] this double iframe nesting. And the [14:11] thing that you will have to make sure to [14:13] do is every time you build an [14:15] application, declare all domains your [14:18] application depends upon inside the [14:20] provided metadata in the MCP app spec so [14:24] that [14:25] you are sure that they will be [14:28] rewritten correctly inside the nested [14:30] iframe. For example, if you are from [14:33] your app connecting to an external API [14:35] to fetch data, you need to reference [14:37] this domain inside the connect SRC [14:38] directive of the [14:40] metadata. [14:41] Same thing for the script, image, [14:44] frame and base UI not so much used, but [14:46] the two first one are very important. [14:48] And [14:49] it's reminded me of a very old problem [14:51] that I had when I started my developer's [14:53] days back in 2016 I think it was. [14:57] As a new [14:59] developer in the space, I was [15:00] experiencing a trouble getting [15:03] cross-origin resource [15:05] security right calls. I had trouble [15:08] getting it right. CSP reminded me of [15:11] those ugly day of not getting right the [15:13] first time with calls. So, there has [15:16] been effort in the ecosystem to make [15:19] builders' life better, [15:21] especially for example on open AI side [15:24] where they activated they added an [15:27] option in developer mode. So, if you're [15:28] a developer and developing app, they [15:30] have a [15:31] specific mode which is developer mode [15:33] which allows you to have access to [15:34] additional features. Up to today, [15:37] when you were in developer mode, all CSP [15:39] were removed. So, you were discovering [15:42] when you were going into production if [15:44] some of your servers could not be [15:45] reached because of missing domains [15:47] inside your CSP, which was not ideal. [15:50] They are not the only one doing a bunch [15:53] of work to make builders' life much [15:54] easier. [15:55] At Alpic, we build an open source [15:57] framework called Skybridge. [15:59] Skybridge is a super set of feature on [16:01] top of the official app SDK either and [16:04] the app we are mentioning. It brings a [16:06] few things to the table, end-to-end type [16:07] safety between your MCP server and your [16:09] app widgets and views. [16:11] You have a lot of APIs that provides [16:14] polyfill for features that are not part [16:16] of the common specification and specific [16:17] to some of the hosts, some of code and [16:19] some of chat GPT APIs. And [16:23] we provide a bunch of modern development [16:26] features especially in the on dev [16:27] environment features. And I wanted to [16:29] show you one just specifically made for [16:32] CSP, which we call the CSP inspector. [16:35] Time for a small demo. [16:37] I do have a few minutes left. Perfect. [16:39] Let me quickly switch to [16:43] my screen. [16:45] Up. [16:50] Uh [16:51] up. [16:54] Okay. [16:55] So, this is [16:59] Um this is an example code base that [17:02] will be generated when you create a new [17:04] Skybridge application. [17:06] This example Skybridge application comes [17:09] with [17:10] a small application. It's a eight ball [17:12] that you can ask any question to that [17:13] will respond one of the 25 predefined [17:16] answer. [17:17] It has [17:19] MCP tool that serves as [17:22] generating the answer and a view that is [17:25] there to display the question and the [17:26] answer to the question that you ask. [17:29] When I start the server of Skybridge, I [17:32] have access in my browser to a dev tool, [17:34] which is basically a small app that will [17:36] give me inspection tooling to work with [17:38] my app before I bring it to chat GPT. [17:41] For example, on the left I have a list [17:42] of tools that are exposed by my app. [17:44] I can if I want ask [17:48] execute any of the tool. So, for example [17:50] here, I'm executing the magic eight ball [17:52] tool. And if there are [17:55] views associated with this tool, [17:57] they will be rendered inside the [17:58] inspector for me to have a closer look [18:00] at it and make changes and see those [18:02] changes reflected live in the UI. [18:04] The neat thing I wanted to demonstrate [18:07] is the CSP part of the inspector that we [18:09] built, which basically looks at all the [18:12] domains that you listed inside your [18:13] metadata and all the domains that are [18:16] actually accessed by calls made by your [18:18] view and compare them to make sure that [18:20] none of them are not listed yet. [18:23] So, for example here, everything's [18:25] green, but if I go back to my actual [18:27] code base and for example [18:30] fetch some API to get [18:32] info about my IP location, [18:35] this [18:36] will be reflected straight away in the [18:38] inspector because the component has been [18:40] re-rendered and I know I have the exact [18:43] domain that I want [18:45] that I just called listed as missing [18:47] from the metadata. And I can go back [18:49] inside my application and add the [18:52] missing domain and now it should appear [18:55] green if I reload it. [18:57] Yeah, everything good. [19:00] So, neat little tool. There are a lot of [19:02] other features that are packed inside [19:03] Skybridge, but that's one of them that [19:05] we made sure to be available to builders [19:07] because we've seen a lot of rejection [19:09] coming from chat GPT app store [19:10] submission because of missing CSP and [19:12] app not working in production because of [19:14] missing CSP domains. [19:16] Um [19:18] Just to finish up quickly if I can. [19:23] Up. [19:24] Uh up. This one. Yeah. [19:27] Um yeah, that's all. Thank you again for [19:30] your time. If you want to grab the [19:32] slides and take a look later on, [19:34] feel free to scan the first QR code. [19:36] If you want to give a try to Skybridge, [19:38] feel free to scan the second one. [19:40] I will run right now a small lottery. We [19:43] have [19:44] ski goggles to win if you star Skybridge [19:46] repo in the next minute or so. [19:49] I will draw name at random and you will [19:51] win a ski ball mask. Thank you very much [19:53] for your attention. [19:55] >> [applause] [20:03] [music]