Describe the bug
When the editor starts a simulator extension (simx) iframe, it passes the editor's embedder origin as the simx's parentOrigin (options.parentOrigin) instead of the editor's own origin. A simx that validates the origin of incoming postMessages against that value (e.g. jacdac's IFrameBridgeClient) then rejects every message the editor forwards to it whenever the editor is embedded cross-origin in controller mode - because those messages arrive with the editor's origin, which never matches the embedder origin the simx was told to trust. Net effect: nothing the host sends reaches the simulator extension.
To Reproduce
Scenario: a host app embeds the editor cross-origin, owns the device connection (e.g. BLE/USB), and relays frames to/from the editor via postMessage.
- Embed the editor in an iframe on a different origin with
controller=2 and parentOrigin=<host origin> (so the editor whitelists the host).
- Run a project that activates a simulator extension whose iframe validates the origin of inbound messages against its
parentOrigin (the Jacdac simx / IFrameBridgeClient does this).
- From the host, post
{ type: "messagepacket", channel: "jacdac", broadcast: true, data } to the editor iframe.
- The simx never receives it; its origin check drops it. (It works when the editor is not embedded, because
parentOrigin is then undefined and the simx falls back to accepting any origin, masking the bug.)
Expected behavior
The simulator extension receives the messages the editor forwards to it (so a host-bridged device shows up). Since the simx's parent window is the editor, it should be given the editor's own origin (window.location.origin) as parentOrigin.
Screenshots
N/A --- the symptom is the simx receiving no forwarded frames (its origin check rejects them).
Desktop:
- OS: Windows 11
- Browser: Chrome 149
- Version: pxt-core 12.3.7 (behavior identical on
master)
Smartphone: N/A
Additional context
In the simulatorExtension start path it does:
|
url.searchParams.set("parentOrigin", encodeURIComponent(this.options.parentOrigin)); |
i.e. the embedder (grandparent) origin, where the simx's actual parent is the editor.
One-line fix candidate: pass window.location.origin instead of this.options.parentOrigin (correct standalone and embedded). Happy to open a PR; open to a different approach if you'd prefer to solve it another way.
Describe the bug
When the editor starts a simulator extension (simx) iframe, it passes the editor's embedder origin as the simx's
parentOrigin(options.parentOrigin) instead of the editor's own origin. A simx that validates the origin of incomingpostMessages against that value (e.g. jacdac'sIFrameBridgeClient) then rejects every message the editor forwards to it whenever the editor is embedded cross-origin in controller mode - because those messages arrive with the editor's origin, which never matches the embedder origin the simx was told to trust. Net effect: nothing the host sends reaches the simulator extension.To Reproduce
Scenario: a host app embeds the editor cross-origin, owns the device connection (e.g. BLE/USB), and relays frames to/from the editor via
postMessage.controller=2andparentOrigin=<host origin>(so the editor whitelists the host).parentOrigin(the Jacdac simx /IFrameBridgeClientdoes this).{ type: "messagepacket", channel: "jacdac", broadcast: true, data }to the editor iframe.parentOriginis then undefined and the simx falls back to accepting any origin, masking the bug.)Expected behavior
The simulator extension receives the messages the editor forwards to it (so a host-bridged device shows up). Since the simx's parent window is the editor, it should be given the editor's own origin (
window.location.origin) asparentOrigin.Screenshots
N/A --- the symptom is the simx receiving no forwarded frames (its origin check rejects them).
Desktop:
master)Smartphone: N/A
Additional context
In the
simulatorExtensionstart path it does:pxt/pxtsim/simdriver.ts
Line 429 in 3aaeddb
i.e. the embedder (grandparent) origin, where the simx's actual parent is the editor.
One-line fix candidate: pass
window.location.origininstead ofthis.options.parentOrigin(correct standalone and embedded). Happy to open a PR; open to a different approach if you'd prefer to solve it another way.