Uh oh!
There was an error while loading. Please reload this page.
fix(basic-host): accept Safari same-origin event.source in sandbox relay - #632
fix(basic-host): accept Safari same-origin event.source in sandbox relay#632ochafik wants to merge 1 commit into
Conversation
Safari/WebKit can surface inner-iframe messages at the sandbox relay with event.source === window (the sandbox's own window) rather than inner.contentWindow. The strict source-identity check then drops the View's ui/initialize and the handshake never completes. Accept that case when event.origin === OWN_ORIGIN — the sandbox runs on its own dedicated origin, so origin is the real security boundary here. Source-identity remains the primary check on Chromium where it works.
ochafik
commented
Apr 21, 2026
@mel-anthropic — could you sanity-check this on Safari/iOS when you get a chance? Kent's runtime evidence (linked above) shows WebKit reporting the inner iframe's |
@modelcontextprotocol/ext-apps@modelcontextprotocol/server-basic-preact@modelcontextprotocol/server-basic-react@modelcontextprotocol/server-basic-solid@modelcontextprotocol/server-basic-svelte@modelcontextprotocol/server-basic-vanillajs@modelcontextprotocol/server-basic-vue@modelcontextprotocol/server-budget-allocator@modelcontextprotocol/server-cohort-heatmap@modelcontextprotocol/server-customer-segmentation@modelcontextprotocol/server-debug@modelcontextprotocol/server-map@modelcontextprotocol/server-pdf@modelcontextprotocol/server-scenario-modeler@modelcontextprotocol/server-shadertoy@modelcontextprotocol/server-sheet-music@modelcontextprotocol/server-system-monitor@modelcontextprotocol/server-threejs@modelcontextprotocol/server-transcript@modelcontextprotocol/server-video-resource@modelcontextprotocol/server-wiki-explorercommit: |
kentcdodds
commented
Apr 21, 2026
I'm not very familiar with the implementation of this project but it is a little disappointing that this fix is in an example because that means that all implementers must also implement this fix. Is there not a library that implementers use so that this fix can be automatically applied to them? |
Summary
Safari/WebKit can surface inner-iframe messages at the sandbox relay with
event.source === window(the sandbox's own window) rather thaninner.contentWindow. The strict source-identity check atsandbox.ts:115then drops the View'sui/initialize, and the handshake never completes — Chromium-based hosts render fine, Safari desktop / iOS WebKit / mobile-native do not.Accept that case when
event.origin === OWN_ORIGIN. The sandbox runs on its own dedicated origin, so origin is the actual security boundary; source-identity was a belt-and-braces check that turns out to be brittle on WebKit. The existing innerevent.origin !== OWN_ORIGINrejection still applies.Diagnosis and fix by @kentcdodds — see the runtime evidence in #542 (comment).
This is separate from the #542 srcdoc construction-timing race (host attaches its listener after the View has already posted), which is being addressed via host-construction-order docs/helper instead of a deferred-target transport (see discussion on #543).
Test plan
npm run --workspace examples/basic-host build— compilesui/initializeand renders