Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: insecure iframe messaging #297

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/transports/PostMessageIframeTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class PostMessageIframeTransport extends Transport {
});
}
private messageHandler = (ev: MessageEvent) => {
this.transportRequestManager.resolveResponse(JSON.stringify(ev.data));
if (ev.origin === this.uri)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (ev.origin === this.uri)
if (ev.origin === this.origin)

this.transportRequestManager.resolveResponse(JSON.stringify(ev.data));
}
public connect(): Promise<any> {
const urlRegex = /^(http|https):\/\/.*$/;
Expand All @@ -46,7 +47,7 @@ class PostMessageIframeTransport extends Transport {
const prom = this.transportRequestManager.addRequest(data, null);
const notifications = getNotifications(data);
if (this.frame) {
this.frame.postMessage((data as IJSONRPCData).request, "*");
this.frame.postMessage((data as IJSONRPCData).request, this.uri);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.frame.postMessage((data as IJSONRPCData).request, this.uri);
this.frame.postMessage((data as IJSONRPCData).request, this.origin);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the origin can easily be derived as new URL(this.uri).origin
We don't need another parameter from ctor

this.transportRequestManager.settlePendingRequest(notifications);
}
return prom;
Expand Down
3 changes: 2 additions & 1 deletion src/transports/PostMessageWindowTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class PostMessageTransport extends Transport {
}

private messageHandler = (ev: MessageEvent) => {
this.transportRequestManager.resolveResponse(JSON.stringify(ev.data));
if (ev.origin === this.uri)
Copy link
Member

@zcstarr zcstarr Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (ev.origin === this.uri)
if (ev.origin === this.origin || ev.orgin === "*")

this.transportRequestManager.resolveResponse(JSON.stringify(ev.data));
}

public connect(): Promise<any> {
Expand Down