Skip to content

Commit ebb603c

Browse files
committed
refactor: ensure redirect security
1 parent 0c5ccc4 commit ebb603c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/routes/(app)/session/redirect/+page.svelte

+14-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
if (!target) return null;
1212
let targetUrl = new URL(target);
1313
14+
if (
15+
![
16+
'.phi.zone',
17+
'.phizone.cn',
18+
'phizone-ui.vercel.app',
19+
'phizone-ui.pages.dev',
20+
'localhost',
21+
].some((host) => (host[0] === '.' ? targetUrl.host.endsWith(host) : targetUrl.host === host))
22+
)
23+
return null;
24+
1425
for (let [key, value] of page.url.searchParams.entries()) {
1526
if (key === 'uri') continue;
1627
targetUrl.searchParams.append(key, value);
@@ -21,11 +32,12 @@
2132
onMount(async () => {
2233
if (browser) {
2334
setTimeout(async () => {
35+
const dest = build(page.url.searchParams.get('uri')) ?? '/';
2436
try {
2537
await Promise.allSettled([useQueryClient().invalidateQueries(), invalidateAll()]);
26-
await goto(build(page.url.searchParams.get('uri')) ?? '/');
38+
await goto(dest);
2739
} catch {
28-
window.location.href = build(page.url.searchParams.get('uri')) ?? '/';
40+
window.location.href = dest;
2941
}
3042
}, 1000);
3143
}

0 commit comments

Comments
 (0)