Skip to content

Commit 093bdb4

Browse files
authored
Check origin of GitHub code postMessages (#579)
It would be suspicious if we received a GitHub code postMessage from any origin other than our own. Part of #533
1 parent 4d6bcb3 commit 093bdb4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/lit-dev-content/src/github/github-signin-receiver-page.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ if (opener) {
2828
} else {
2929
message = {code};
3030
}
31+
// Note the default postMessage targetOrigin is "/"
32+
// (https://html.spec.whatwg.org/multipage/web-messaging.html#posting-messages)
33+
// so by leaving it unspecified we ensure that we will only post codes to our
34+
// expected same-origin.
3135
opener.postMessage(message);
3236
} else {
3337
const p = document.createElement('p');

packages/lit-dev-content/src/github/github-signin.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,11 @@ const receiveCodeFromPopup = (
122122
'message',
123123
(event) => {
124124
// Note we must check source because our popup might not be the only
125-
// source of "message" events. This is also why we can't set "once".
126-
if (event.source === popup) {
125+
// source of "message" events. This is also why we can't set "once". We
126+
// also check the origin because we expect GitHub to redirect to the
127+
// receiver page running on the same origin as this page; any other
128+
// origin would be suspicious (or a misconfiguration).
129+
if (event.source === popup && event.origin === window.location.origin) {
127130
resolve(event.data);
128131
abort();
129132
}

0 commit comments

Comments
 (0)