File tree Expand file tree Collapse file tree 4 files changed +27
-37
lines changed
Expand file tree Collapse file tree 4 files changed +27
-37
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {
1515 ModalHeader ,
1616} from '@/components/emcn'
1717import { client } from '@/lib/auth/auth-client'
18+ import { validateCallbackUrl } from '@/lib/auth/validate-callback-url'
1819import { getEnv , isFalsy , isTruthy } from '@/lib/core/config/env'
1920import { cn } from '@/lib/core/utils/cn'
2021import { getBaseUrl } from '@/lib/core/utils/urls'
@@ -53,24 +54,6 @@ const PASSWORD_VALIDATIONS = {
5354 } ,
5455}
5556
56- const validateCallbackUrl = ( url : string ) : boolean => {
57- try {
58- if ( url . startsWith ( '/' ) ) {
59- return true
60- }
61-
62- const currentOrigin = typeof window !== 'undefined' ? window . location . origin : ''
63- if ( url . startsWith ( currentOrigin ) ) {
64- return true
65- }
66-
67- return false
68- } catch ( error ) {
69- logger . error ( 'Error validating callback URL:' , { error, url } )
70- return false
71- }
72- }
73-
7457const validatePassword = ( passwordValue : string ) : string [ ] => {
7558 const errors : string [ ] = [ ]
7659
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ 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'
910import { env , isFalsy } from '@/lib/core/config/env'
1011import { cn } from '@/lib/core/utils/cn'
1112import { quickValidateEmail } from '@/lib/messaging/email/validation'
@@ -29,24 +30,6 @@ const validateEmailField = (emailValue: string): string[] => {
2930 return errors
3031}
3132
32- const validateCallbackUrl = ( url : string ) : boolean => {
33- try {
34- if ( url . startsWith ( '/' ) ) {
35- return true
36- }
37-
38- const currentOrigin = typeof window !== 'undefined' ? window . location . origin : ''
39- if ( url . startsWith ( currentOrigin ) ) {
40- return true
41- }
42-
43- return false
44- } catch ( error ) {
45- logger . error ( 'Error validating callback URL:' , { error, url } )
46- return false
47- }
48- }
49-
5033export default function SSOForm ( ) {
5134 const router = useRouter ( )
5235 const searchParams = useSearchParams ( )
Original file line number Diff line number Diff line change 1+ import { createLogger } from '@sim/logger'
2+
3+ const logger = createLogger ( 'ValidateCallbackUrl' )
4+
5+ /**
6+ * Returns true if the URL is safe to redirect to after authentication.
7+ * Accepts relative paths and absolute URLs matching the current origin.
8+ */
9+ export function validateCallbackUrl ( url : string ) : boolean {
10+ try {
11+ if ( url . startsWith ( '/' ) ) return true
12+
13+ const currentOrigin = typeof window !== 'undefined' ? window . location . origin : ''
14+ if ( url . startsWith ( currentOrigin ) ) return true
15+
16+ return false
17+ } catch ( error ) {
18+ logger . error ( 'Error validating callback URL:' , { error, url } )
19+ return false
20+ }
21+ }
Original file line number Diff line number Diff line change @@ -132,7 +132,10 @@ export async function isDisposableMxBackend(email: string): Promise<boolean> {
132132
133133 const now = Date . now ( )
134134 const cached = mxCache . get ( domain )
135- if ( cached && cached . expires > now ) return cached . result
135+ if ( cached ) {
136+ if ( cached . expires > now ) return cached . result
137+ mxCache . delete ( domain )
138+ }
136139
137140 let timeoutId : ReturnType < typeof setTimeout > | undefined
138141 try {
You can’t perform that action at this time.
0 commit comments