Skip to content

Commit

Permalink
Tweak origin check to respect the configured URL
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-matt-hillsdon committed Sep 10, 2024
1 parent aaa463d commit e08e461
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/vanilla/makecode-frame-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,22 @@ export class MakeCodeFrameDriver {
}
>();

private _expectedOrigin: string | undefined;
private expectedOrigin = () => {
if (this._expectedOrigin) {
return this._expectedOrigin;
}
const src = this.iframe()?.src;
if (src) {
this._expectedOrigin = new URL(src).origin;
return this._expectedOrigin;
}
return undefined;
};

private listener = (event: MessageEvent) => {
if (event.origin !== 'https://makecode.microbit.org') {
const expectedOrigin = this.expectedOrigin();
if (!expectedOrigin || event.origin !== expectedOrigin) {
return;
}
const { data } = event;
Expand Down

0 comments on commit e08e461

Please sign in to comment.