mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 10:22:55 +08:00
fix(core): unable to redirect to same origin paths (#6586)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { DebugLogger } from '@affine/debug';
|
||||||
import { type LoaderFunction, Navigate, useLoaderData } from 'react-router-dom';
|
import { type LoaderFunction, Navigate, useLoaderData } from 'react-router-dom';
|
||||||
|
|
||||||
const trustedDomain = [
|
const trustedDomain = [
|
||||||
@@ -10,6 +11,8 @@ const trustedDomain = [
|
|||||||
'reddit.com',
|
'reddit.com',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const logger = new DebugLogger('redirect_proxy');
|
||||||
|
|
||||||
export const loader: LoaderFunction = async ({ request }) => {
|
export const loader: LoaderFunction = async ({ request }) => {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const searchParams = url.searchParams;
|
const searchParams = url.searchParams;
|
||||||
@@ -19,14 +22,21 @@ export const loader: LoaderFunction = async ({ request }) => {
|
|||||||
return { allow: false };
|
return { allow: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
const target = new URL(redirectUri);
|
try {
|
||||||
|
const target = new URL(redirectUri);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
trustedDomain.some(domain =>
|
target.hostname === window.location.hostname ||
|
||||||
new RegExp(`.?${domain}$`).test(target.hostname)
|
trustedDomain.some(domain =>
|
||||||
)
|
new RegExp(`.?${domain}$`).test(target.hostname)
|
||||||
) {
|
)
|
||||||
location.href = redirectUri;
|
) {
|
||||||
|
location.href = redirectUri;
|
||||||
|
return { allow: true };
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('Failed to parse redirect uri', e);
|
||||||
|
return { allow: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
return { allow: true };
|
return { allow: true };
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
export function popupWindow(target: string) {
|
export function popupWindow(target: string) {
|
||||||
const url = new URL(runtimeConfig.serverUrlPrefix + '/redirect-proxy');
|
const url = new URL(runtimeConfig.serverUrlPrefix + '/redirect-proxy');
|
||||||
|
target = /^https?:\/\//.test(target)
|
||||||
|
? target
|
||||||
|
: runtimeConfig.serverUrlPrefix + target;
|
||||||
url.searchParams.set('redirect_uri', target);
|
url.searchParams.set('redirect_uri', target);
|
||||||
|
|
||||||
return window.open(url, '_blank', `noreferrer noopener`);
|
return window.open(url, '_blank', `noreferrer noopener`);
|
||||||
|
|||||||
Reference in New Issue
Block a user