Skip to content

Simulator extension receives the embedder's origin as parentOrigin, not the editor's — breaks host→simx messaging when the editor is embedded cross-origin #11446

Description

@Amerlander

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.

  1. Embed the editor in an iframe on a different origin with controller=2 and parentOrigin=<host origin> (so the editor whitelists the host).
  2. 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).
  3. From the host, post { type: "messagepacket", channel: "jacdac", broadcast: true, data } to the editor iframe.
  4. 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.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions