Skip to content

Commit 23131d1

Browse files
committed
ack PR comments
1 parent 0b43d6f commit 23131d1

File tree

4 files changed

+28
-33
lines changed

4 files changed

+28
-33
lines changed

apps/sim/app/api/auth/forget-password/route.test.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,8 @@
66
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
77
import { createMockRequest, setupAuthApiMocks } from '@/app/api/__test-utils__/utils'
88

9-
vi.mock('@/lib/core/config/env', () => ({
10-
getEnv: vi.fn((key: string) => {
11-
if (key === 'NEXT_PUBLIC_APP_URL') {
12-
return 'https://app.example.com'
13-
}
14-
return undefined
15-
}),
9+
vi.mock('@/lib/core/utils/urls', () => ({
10+
getBaseUrl: vi.fn(() => 'https://app.example.com'),
1611
}))
1712

1813
describe('Forget Password API Route', () => {
@@ -72,7 +67,7 @@ describe('Forget Password API Route', () => {
7267
const data = await response.json()
7368

7469
expect(response.status).toBe(400)
75-
expect(data.message).toBe('Redirect URL must be same-origin')
70+
expect(data.message).toBe('Redirect URL must be a valid same-origin URL')
7671

7772
const auth = await import('@/lib/auth')
7873
expect(auth.auth.api.forgetPassword).not.toHaveBeenCalled()

apps/sim/app/api/auth/forget-password/route.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ const forgetPasswordSchema = z.object({
1414
.email('Please provide a valid email address'),
1515
redirectTo: z
1616
.string()
17-
.url('Redirect URL must be a valid URL')
18-
.refine((url) => isSameOrigin(url), {
19-
message: 'Redirect URL must be same-origin',
20-
})
2117
.optional()
2218
.or(z.literal(''))
23-
.transform((val) => (val === '' ? undefined : val)),
19+
.transform((val) => (val === '' || val === undefined ? undefined : val))
20+
.refine(
21+
(val) => val === undefined || (z.string().url().safeParse(val).success && isSameOrigin(val)),
22+
{
23+
message: 'Redirect URL must be a valid same-origin URL',
24+
}
25+
),
2426
})
2527

2628
export async function POST(request: NextRequest) {

apps/sim/lib/core/config/feature-flags.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
/**
22
* Environment utility functions for consistent environment detection across the application
33
*/
4-
5-
import { createLogger } from '@/lib/logs/console/logger'
64
import { env, getEnv, isTruthy } from './env'
75

8-
const logger = createLogger('FeatureFlags')
9-
106
/**
117
* Is the application running in production mode
128
*/
@@ -46,16 +42,22 @@ export const isEmailVerificationEnabled = isTruthy(env.EMAIL_VERIFICATION_ENABLE
4642
export const isAuthDisabled = isTruthy(env.DISABLE_AUTH) && !isHosted
4743

4844
if (isTruthy(env.DISABLE_AUTH)) {
49-
if (isHosted) {
50-
logger.error(
51-
'DISABLE_AUTH is set but ignored on hosted environment. Authentication remains enabled for security.'
52-
)
53-
} else {
54-
logger.warn(
55-
'DISABLE_AUTH is enabled. Authentication is bypassed and all requests use an anonymous session. ' +
56-
'Only use this in trusted private networks.'
57-
)
58-
}
45+
import('@/lib/logs/console/logger')
46+
.then(({ createLogger }) => {
47+
const logger = createLogger('FeatureFlags')
48+
if (isHosted) {
49+
logger.error(
50+
'DISABLE_AUTH is set but ignored on hosted environment. Authentication remains enabled for security.'
51+
)
52+
} else {
53+
logger.warn(
54+
'DISABLE_AUTH is enabled. Authentication is bypassed and all requests use an anonymous session. Only use this in trusted private networks.'
55+
)
56+
}
57+
})
58+
.catch(() => {
59+
// Fallback during config compilation when logger is unavailable
60+
})
5961
}
6062

6163
/**

apps/sim/lib/core/utils/validation.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getEnv } from '@/lib/core/config/env'
1+
import { getBaseUrl } from './urls'
22

33
/**
44
* Checks if a URL is same-origin with the application's base URL.
@@ -9,12 +9,8 @@ import { getEnv } from '@/lib/core/config/env'
99
*/
1010
export function isSameOrigin(url: string): boolean {
1111
try {
12-
const appBaseUrl = getEnv('NEXT_PUBLIC_APP_URL')
13-
if (!appBaseUrl) {
14-
return false
15-
}
1612
const targetUrl = new URL(url)
17-
const appUrl = new URL(appBaseUrl)
13+
const appUrl = new URL(getBaseUrl())
1814
return targetUrl.origin === appUrl.origin
1915
} catch {
2016
return false

0 commit comments

Comments
 (0)