Skip to content

Commit 1508f81

Browse files
committed
fix(security): revert CORS origin restriction for embedded deployments
Embedded chat widgets and forms are designed to run on any customer domain. Restricting CORS to an allowlist would break all existing embedded deployments.
1 parent 7d045f5 commit 1508f81

File tree

1 file changed

+3
-37
lines changed

1 file changed

+3
-37
lines changed

apps/sim/lib/core/security/deployment.ts

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { createHash } from 'crypto'
22
import type { NextRequest, NextResponse } from 'next/server'
3-
import { getEnv } from '@/lib/core/config/env'
43
import { isDev } from '@/lib/core/config/feature-flags'
5-
import { getBaseUrl } from '@/lib/core/utils/urls'
64

75
/**
86
* Shared authentication utilities for deployed chat and form endpoints.
@@ -82,47 +80,15 @@ export function setDeploymentAuthCookie(
8280
})
8381
}
8482

85-
/**
86-
* Returns the set of origins allowed for cross-origin requests.
87-
* Includes the app's own origin and any origins from ALLOWED_ORIGINS env var.
88-
* In development, localhost origins are also permitted.
89-
*/
90-
function getAllowedOrigins(): Set<string> {
91-
const origins = new Set<string>()
92-
93-
try {
94-
const appOrigin = new URL(getBaseUrl()).origin
95-
origins.add(appOrigin)
96-
} catch {
97-
// getBaseUrl() may throw if NEXT_PUBLIC_APP_URL is not configured
98-
}
99-
100-
const envOrigins = getEnv('ALLOWED_ORIGINS')
101-
if (envOrigins) {
102-
for (const raw of envOrigins.split(',')) {
103-
const trimmed = raw.trim()
104-
if (trimmed) {
105-
origins.add(trimmed)
106-
}
107-
}
108-
}
109-
110-
if (isDev) {
111-
origins.add('http://localhost:3000')
112-
origins.add('http://localhost:3001')
113-
}
114-
115-
return origins
116-
}
117-
11883
/**
11984
* Adds CORS headers to allow cross-origin requests for embedded deployments.
120-
* Only reflects the origin if it is in the allowed origins list.
85+
* Embedded chat widgets and forms are designed to run on any customer domain,
86+
* so we reflect the requesting origin rather than restricting to an allowlist.
12187
*/
12288
export function addCorsHeaders(response: NextResponse, request: NextRequest): NextResponse {
12389
const origin = request.headers.get('origin') || ''
12490

125-
if (origin && getAllowedOrigins().has(origin)) {
91+
if (origin) {
12692
response.headers.set('Access-Control-Allow-Origin', origin)
12793
response.headers.set('Access-Control-Allow-Credentials', 'true')
12894
response.headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')

0 commit comments

Comments
 (0)