Skip to content

Commit

Permalink
fix: remove ev origin guard for postmessage + ignore non JSON-RPC mes…
Browse files Browse the repository at this point in the history
…sages
  • Loading branch information
shanejonas committed Apr 8, 2021
1 parent 7909cd9 commit ef2dc2f
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 17 deletions.
3 changes: 0 additions & 3 deletions src/transports/PostMessageIframeTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class PostMessageIframeTransport extends Transport {
});
}
private messageHandler = (ev: MessageEvent) => {
if (ev.origin === window.origin) {
return;
}
this.transportRequestManager.resolveResponse(JSON.stringify(ev.data));
}
public connect(): Promise<any> {
Expand Down
3 changes: 0 additions & 3 deletions src/transports/PostMessageWindowTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ class PostMessageTransport extends Transport {
}

private messageHandler = (ev: MessageEvent) => {
if (ev.origin === window.origin) {
return;
}
this.transportRequestManager.resolveResponse(JSON.stringify(ev.data));
}

Expand Down
12 changes: 2 additions & 10 deletions src/transports/TransportRequestManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,9 @@ describe("Transport Request Manager", () => {
transportReqMan.settlePendingRequest([request], new Error("rejecting"));
});

it("should emit error on bad format for resolving a response", (done) => {
transportReqMan.transportEventChannel.on("error", (err) => {
expect(err.message).toContain("Bad response format");
done();
});
it("should not error on bad format for resolving a response", (done) => {
transportReqMan.resolveResponse("{}");
});

it("should not emit error on bad format for resolving a response", () => {
const err = transportReqMan.resolveResponse("{}", false) as Error;
expect(err.message).toContain("Bad response format");
done();
});

it("should emit response on response && resolve response", (done) => {
Expand Down
2 changes: 1 addition & 1 deletion src/transports/TransportRequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class TransportRequestManager {
try {
data = JSON.parse(payload);
if (this.checkJSONRPC(data) === false) {
throw new Error("Bad response format");
return; // ignore messages that are not conforming to JSON-RPC
}
if (data instanceof Array) {
return this.resolveBatch(data, emitError);
Expand Down

0 comments on commit ef2dc2f

Please sign in to comment.