fix(basic-host): accept Safari same-origin event.source in sandbox relay#632
Open
fix(basic-host): accept Safari same-origin event.source in sandbox relay#632
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.
Contributor
Author
|
@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-explorer
commit: |
|
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? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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