File tree Expand file tree Collapse file tree 2 files changed +10
-9
lines changed
dashboard/src/app/(dashboard)/onboarding
status-page/src/app/(status-page)/[domain]/(auth)/login/_components Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 />
You can’t perform that action at this time.
0 commit comments