Skip to content

Commit dd06585

Browse files
committed
make validation on http more lax
1 parent cc33742 commit dd06585

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

apps/sim/app/api/copilot/checkpoints/revert/route.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ describe('Copilot Checkpoints Revert API Route', () => {
1818
setupCommonApiMocks()
1919
mockCryptoUuid()
2020

21-
// Mock getBaseUrl to return localhost for tests
2221
vi.doMock('@/lib/core/utils/urls', () => ({
2322
getBaseUrl: vi.fn(() => 'http://localhost:3000'),
23+
getInternalApiBaseUrl: vi.fn(() => 'http://localhost:3000'),
2424
getBaseDomain: vi.fn(() => 'localhost:3000'),
2525
getEmailDomain: vi.fn(() => 'localhost:3000'),
2626
}))

apps/sim/app/api/mcp/serve/[serverId]/route.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe('MCP Serve Route', () => {
7272
}))
7373
vi.doMock('@/lib/core/utils/urls', () => ({
7474
getBaseUrl: () => 'http://localhost:3000',
75+
getInternalApiBaseUrl: () => 'http://localhost:3000',
7576
}))
7677
vi.doMock('@/lib/core/execution-limits', () => ({
7778
getMaxExecutionTimeout: () => 10_000,

apps/sim/lib/core/config/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export const env = createEnv({
220220
SOCKET_SERVER_URL: z.string().url().optional(), // WebSocket server URL for real-time features
221221
SOCKET_PORT: z.number().optional(), // Port for WebSocket server
222222
PORT: z.number().optional(), // Main application port
223-
INTERNAL_API_BASE_URL: z.string().optional(), // Optional internal base URL for server-side self-calls (e.g., cluster DNS)
223+
INTERNAL_API_BASE_URL: z.string().optional(), // Optional internal base URL for server-side self-calls; must include protocol if set (e.g., http://sim-app.namespace.svc.cluster.local:3000)
224224
ALLOWED_ORIGINS: z.string().optional(), // CORS allowed origins
225225

226226
// OAuth Integration Credentials - All optional, enables third-party integrations

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { getEnv } from '@/lib/core/config/env'
22
import { isProd } from '@/lib/core/config/feature-flags'
33

4+
function hasHttpProtocol(url: string): boolean {
5+
return /^https?:\/\//i.test(url)
6+
}
7+
48
function normalizeBaseUrl(url: string): string {
5-
if (url.startsWith('http://') || url.startsWith('https://')) {
9+
if (hasHttpProtocol(url)) {
610
return url
711
}
812

@@ -17,7 +21,7 @@ function normalizeBaseUrl(url: string): string {
1721
* @throws Error if NEXT_PUBLIC_APP_URL is not configured
1822
*/
1923
export function getBaseUrl(): string {
20-
const baseUrl = getEnv('NEXT_PUBLIC_APP_URL')
24+
const baseUrl = getEnv('NEXT_PUBLIC_APP_URL')?.trim()
2125

2226
if (!baseUrl) {
2327
throw new Error(
@@ -38,7 +42,13 @@ export function getInternalApiBaseUrl(): string {
3842
return getBaseUrl()
3943
}
4044

41-
return normalizeBaseUrl(internalBaseUrl)
45+
if (!hasHttpProtocol(internalBaseUrl)) {
46+
throw new Error(
47+
'INTERNAL_API_BASE_URL must include protocol (http:// or https://), e.g. http://sim-app.default.svc.cluster.local:3000'
48+
)
49+
}
50+
51+
return internalBaseUrl
4252
}
4353

4454
/**

helm/sim/values.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
"const": ""
131131
}
132132
],
133-
"description": "Optional server-side internal base URL for internal /api self-calls; defaults to NEXT_PUBLIC_APP_URL when unset"
133+
"description": "Optional server-side internal base URL for internal /api self-calls (must include http:// or https://); defaults to NEXT_PUBLIC_APP_URL when unset"
134134
},
135135
"BETTER_AUTH_URL": {
136136
"type": "string",

helm/sim/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ app:
7070
# Application URLs
7171
NEXT_PUBLIC_APP_URL: "http://localhost:3000"
7272
BETTER_AUTH_URL: "http://localhost:3000"
73-
INTERNAL_API_BASE_URL: "" # Optional server-side internal base URL for /api self-calls; falls back to NEXT_PUBLIC_APP_URL when empty
73+
INTERNAL_API_BASE_URL: "" # Optional server-side internal base URL for /api self-calls (include http:// or https://); falls back to NEXT_PUBLIC_APP_URL when empty
7474
# SOCKET_SERVER_URL: Auto-detected when realtime.enabled=true (uses internal service)
7575
# Only set this if using an external WebSocket service with realtime.enabled=false
7676
NEXT_PUBLIC_SOCKET_URL: "http://localhost:3002" # Public WebSocket URL for browsers

0 commit comments

Comments
 (0)