|
1 | 1 | import { createHash } from 'crypto' |
2 | 2 | import type { NextRequest, NextResponse } from 'next/server' |
3 | | -import { getEnv } from '@/lib/core/config/env' |
4 | 3 | import { isDev } from '@/lib/core/config/feature-flags' |
5 | | -import { getBaseUrl } from '@/lib/core/utils/urls' |
6 | 4 |
|
7 | 5 | /** |
8 | 6 | * Shared authentication utilities for deployed chat and form endpoints. |
@@ -82,47 +80,15 @@ export function setDeploymentAuthCookie( |
82 | 80 | }) |
83 | 81 | } |
84 | 82 |
|
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 | | - |
118 | 83 | /** |
119 | 84 | * 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. |
121 | 87 | */ |
122 | 88 | export function addCorsHeaders(response: NextResponse, request: NextRequest): NextResponse { |
123 | 89 | const origin = request.headers.get('origin') || '' |
124 | 90 |
|
125 | | - if (origin && getAllowedOrigins().has(origin)) { |
| 91 | + if (origin) { |
126 | 92 | response.headers.set('Access-Control-Allow-Origin', origin) |
127 | 93 | response.headers.set('Access-Control-Allow-Credentials', 'true') |
128 | 94 | response.headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS') |
|
0 commit comments