Skip to content

Commit be4c8e4

Browse files
authored
chore: improve callback url (#1981)
1 parent 43d9b2b commit be4c8e4

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

apps/dashboard/src/app/(dashboard)/onboarding/client.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,16 @@ export function Client() {
130130

131131
useEffect(() => {
132132
if (!callbackUrl) return;
133-
// Ignore base URL redirects - only redirect for meaningful paths (e.g., /invite?token=...)
133+
// Validate and normalize the callbackUrl to prevent XSS via javascript: or other dangerous schemes
134134
try {
135135
const url = new URL(callbackUrl, window.location.origin);
136136
if (url.pathname === "/" || url.pathname === "") return;
137-
// Only allow same-origin redirects with safe protocols
138137
if (url.origin !== window.location.origin) return;
139138
if (url.protocol !== "http:" && url.protocol !== "https:") return;
140-
router.push(callbackUrl);
139+
// Navigate using the parsed URL to avoid raw-input parsing discrepancies
140+
router.push(`${url.pathname}${url.search}${url.hash}`);
141141
} catch {
142-
// If callbackUrl is a relative path, check it directly
143-
if (callbackUrl === "/" || callbackUrl === "") return;
144-
// Only allow paths starting with / to prevent protocol-based attacks
145-
if (!callbackUrl.startsWith("/")) return;
146-
router.push(callbackUrl);
142+
// Malformed URLs are not safe to navigate to
147143
}
148144
}, [callbackUrl, router]);
149145

apps/status-page/src/app/(status-page)/[domain]/(auth)/login/_components/section-password.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ export function SectionPassword() {
4343
if (result) {
4444
setPassword(values.password);
4545
const redirect = searchParams.get("redirect");
46-
router.push(redirect ?? "/");
46+
// Only allow safe relative paths to prevent XSS via javascript: URLs
47+
if (redirect?.startsWith("/") && !redirect.startsWith("//")) {
48+
router.push(redirect);
49+
} else {
50+
router.push("/");
51+
}
4752
}
4853
}}
4954
/>

0 commit comments

Comments
 (0)