Skip to content

Commit 950ffb6

Browse files
Ryz0ndchihunmanse
authored andcommitted
attached: pass host_origin to reauth popup to fix cross-origin postMessage
1 parent 105e565 commit 950ffb6

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

apps/user_dashboard/src/app/export_private_key/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ const Page = () => {
539539
`width=${popupWidth},height=${popupHeight},left=${popupLeft},top=${popupTop},resizable=yes`,
540540
);
541541
if (popup) {
542-
popup.location.href = `${attachedOrigin}/export/reauth?auth_type=${authType}&email=${encodeURIComponent(email ?? "")}`;
542+
popup.location.href = `${attachedOrigin}/export/reauth?auth_type=${authType}&email=${encodeURIComponent(email ?? "")}&host_origin=${encodeURIComponent(window.location.origin)}`;
543543
}
544544

545545
// 2. Send export request to attached iframe

embed/oko_attached/src/components/export/use_export_reauth.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ export function findEmbeddedIframe(): Window | null {
3232
return null;
3333
}
3434

35+
function getHostOrigin(): string {
36+
const params = new URLSearchParams(window.location.search);
37+
const hostOrigin = params.get("host_origin");
38+
if (hostOrigin) {
39+
return hostOrigin;
40+
}
41+
return window.location.origin;
42+
}
43+
3544
export function sendReauthParamsToIframe(
3645
iframe: Window,
3746
params: { nonce?: string; code_verifier?: string },
@@ -55,7 +64,7 @@ function buildGoogleOAuthUrl(nonce: string): string {
5564

5665
const oauthState: OAuthState = {
5766
apiKey: "export_key_reauth",
58-
targetOrigin: window.location.origin,
67+
targetOrigin: getHostOrigin(),
5968
provider: "google",
6069
};
6170

@@ -76,7 +85,7 @@ function buildXOAuthUrl(codeChallenge: string): string {
7685

7786
const oauthState: OAuthState = {
7887
apiKey: "export_key_reauth",
79-
targetOrigin: window.location.origin,
88+
targetOrigin: getHostOrigin(),
8089
provider: "x",
8190
};
8291
const oauthStateString = btoa(JSON.stringify(oauthState));
@@ -98,7 +107,7 @@ function buildDiscordOAuthUrl(codeChallenge: string): string {
98107

99108
const oauthState: OAuthState = {
100109
apiKey: "export_key_reauth",
101-
targetOrigin: window.location.origin,
110+
targetOrigin: getHostOrigin(),
102111
provider: "discord",
103112
};
104113
const oauthStateString = btoa(JSON.stringify(oauthState));
@@ -120,7 +129,7 @@ function buildGithubOAuthUrl(codeChallenge: string): string {
120129

121130
const oauthState: OAuthState = {
122131
apiKey: "export_key_reauth",
123-
targetOrigin: window.location.origin,
132+
targetOrigin: getHostOrigin(),
124133
provider: "github",
125134
};
126135
const oauthStateString = btoa(JSON.stringify(oauthState));

0 commit comments

Comments
 (0)