Repository navigation
fix(core): the preview runtime's editing port ignores later changes to MessagePort and window.parent - #8963
fix(core): the preview runtime's editing port ignores later changes to MessagePort and window.parent#8963miguel-heygen wants to merge 3 commits into
Conversation
…o MessagePort and window.parent Port calls use the browser's own methods, read when the runtime first evaluates. The agent hands its port to the parent the frame loaded with.
jerry-heygen
left a comment
There was a problem hiding this comment.
Changes requested at 66b24c03. Capturing the native port methods is the right direction, but the helper still depends on mutable page-realm operations when it uses those methods after composition code has run. The privileged port path should use only operations captured at runtime startup and should not fall back to page-controlled methods on a real port. Please add a regression for that boundary, not only for direct replacement of MessagePort methods.
I verified all eight effective changes against the current test merge. This is a source finding; I did not run a browser reproduction.
— Jerrai (pr-review)
Edit accuracy: accurate 273 (base branch 271), smooth 66 of thoseThe gate passes. Newly passing (2)
Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)
Quarantined, measured but not gated (0) |
… use built-ins read at load Covers the channel's port getters, MessageEvent data and the Maps that hold ports. Native calls go through Reflect.apply read at load.
|
Covered now, all read when the runtime first evaluates and called through a
Not covered: a built-in the runtime reaches with a port by some other route after load. Page script shares this realm, so the frame side cannot fully close that. The checks that matter for what Studio does with frame messages belong on the Studio side. Test added: |
jerry-heygen
left a comment
There was a problem hiding this comment.
Changes requested at 3bebf863. The captured invocation, channel accessors, event-data read, and port collections address most of my previous review. One part remains: the production helpers still use the stand-in path if native capture or port recognition fails. In an editing session that means the code can silently fall back to the page’s methods instead of stopping the connection. Please keep the stand-in adapter explicit for tests and fail closed for Studio’s browser channel if the native methods aren’t available. This doesn’t require making the shared realm a security boundary.
The hosted runtime suite passed at this head. The separate CLI shard failed in received-record fixture cleanup (ENOTEMPTY); that is not the reason for this hold. I did not run a browser reproduction.
— Jerrai (pr-review)
What
The preview runtime's editing port keeps using the browser's own
MessagePortmethods and the frame's original parent, even when a page script later changesMessagePort.prototypeor assignswindow.parent.Why
The runtime evaluates before the page's own scripts, but it set the port's
onmessageand calledpostMessageandclosethroughMessagePort.prototypeat call time. So a page script that patched those methods saw every port the runtime opened, and could post on it as if it were the runtime.installEditingAgentalso readwindow.parentwhen it installed, which happens after the page's scripts run, and a page can assign that property.canvasKeys.tsalready readpostMessageearly; the other port users did not.How
runtime/runtimePort.tsreadsMessageChannel,postMessage,closeand theonmessagesetter from a probe channel when the runtime first evaluates. It exposescreateRuntimeChannel,postOnPort,onPortMessageandclosePort. Those use the stored methods for any browser port and fall back to the object's own methods for a stand-in object, as in tests.watchGeometry,textEdit,stageAct,pausedFramesandcanvasKeysuse them for every port call.canvasKeysdrops its own copy of the same lookup.installEditingAgentdefaults its parent towindow.parentas read when the module evaluated.No visible change
The editing protocol and every message are unchanged. Studio works the same as before.
Test plan
editingAgent.portCapture.test.ts. "keeps its port from a composition that patched MessagePort before Studio connected" patchesonmessageandpostMessageafter the runtime loads, then connects and talks to the agent. It checks that the patches saw no runtime port and that a Delete posted through anything they saw never reaches the parent. "hands its port to the parent it loaded with, not one a composition put on window.parent" assignswindow.parentbefore install and checks that the port is never handed to it.editingAgent.portCapture.test.tsfail with the six runtime files atmain, and pass with this change.test:hyperframe-runtime-ciexits 0.tsc --noEmitis clean. The Studio sealed-keys, sealed, preview-channel, stage-act and dom-edit-session suites pass against the rebuilt core (112 tests).