File tree Expand file tree Collapse file tree 4 files changed +23
-23
lines changed
Expand file tree Collapse file tree 4 files changed +23
-23
lines changed Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ import {
1515 ModalHeader ,
1616} from '@/components/emcn'
1717import { client } from '@/lib/auth/auth-client'
18- import { validateCallbackUrl } from '@/lib/auth/validate-callback-url'
1918import { getEnv , isFalsy , isTruthy } from '@/lib/core/config/env'
19+ import { validateCallbackUrl } from '@/lib/core/security/input-validation'
2020import { cn } from '@/lib/core/utils/cn'
2121import { getBaseUrl } from '@/lib/core/utils/urls'
2222import { quickValidateEmail } from '@/lib/messaging/email/validation'
Original file line number Diff line number Diff line change @@ -6,8 +6,8 @@ import Link from 'next/link'
66import { useRouter , useSearchParams } from 'next/navigation'
77import { Button , Input , Label } from '@/components/emcn'
88import { client } from '@/lib/auth/auth-client'
9- import { validateCallbackUrl } from '@/lib/auth/validate-callback-url'
109import { env , isFalsy } from '@/lib/core/config/env'
10+ import { validateCallbackUrl } from '@/lib/core/security/input-validation'
1111import { cn } from '@/lib/core/utils/cn'
1212import { quickValidateEmail } from '@/lib/messaging/email/validation'
1313import { BrandedButton } from '@/app/(auth)/components/branded-button'
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -1169,3 +1169,24 @@ export function validatePaginationCursor(
11691169
11701170 return { isValid : true , sanitized : value }
11711171}
1172+
1173+ /**
1174+ * Validates a callback URL to prevent open redirect attacks.
1175+ * Accepts relative paths and absolute URLs matching the current origin.
1176+ *
1177+ * @param url - The callback URL to validate
1178+ * @returns true if the URL is safe to redirect to
1179+ */
1180+ export function validateCallbackUrl ( url : string ) : boolean {
1181+ try {
1182+ if ( url . startsWith ( '/' ) ) return true
1183+
1184+ const currentOrigin = typeof window !== 'undefined' ? window . location . origin : ''
1185+ if ( url . startsWith ( currentOrigin ) ) return true
1186+
1187+ return false
1188+ } catch ( error ) {
1189+ logger . error ( 'Error validating callback URL:' , { error, url } )
1190+ return false
1191+ }
1192+ }
You can’t perform that action at this time.
0 commit comments