fix(frontend): sanitize redirect targets to prevent XSS/open redirect

Sanitize and validate redirect targets from callbackUrl parameter and sessionStorage in login, registration, and OAuth callback flows.
Introduced safeRedirectTarget helper which rejects protocol-relative URLs, non-relative schemes, control characters, backslashes, and encoding bypasses.
This commit is contained in:
ryan
2026-06-13 09:51:30 +08:00
parent 50d21b431b
commit f48426dbf8
4 changed files with 61 additions and 4 deletions
+3 -1
View File
@@ -14,6 +14,7 @@ import {Field, FieldGroup, FieldLabel} from "@/components/ui/field"
import {AuthHeading} from "@/components/auth/auth-shell"
import services from "@/lib/services"
import type {RegisterRequest} from "@/lib/services/auth/types"
import {safeRedirectTarget} from "@/lib/utils"
function getRedirectTarget(searchParams: ReturnType<typeof useSearchParams>) {
const callbackUrl = searchParams.get("callbackUrl")
@@ -21,9 +22,10 @@ function getRedirectTarget(searchParams: ReturnType<typeof useSearchParams>) {
typeof window === "undefined"
? null
: sessionStorage.getItem("redirect_after_login")
return callbackUrl || storedRedirect || "/home"
return safeRedirectTarget(callbackUrl || storedRedirect || "/home")
}
function configBool(value: string | undefined, fallback: boolean) {
if (value === undefined) return fallback
return value === "true"