Commit ef14b2b
fix(security): remove localhost CORS origin, consolidate CORS in proxy (#4658)
* fix(security): remove localhost CORS origin, consolidate CORS in proxy
Move all /api/* CORS handling from next.config.ts to proxy.ts so the
runtime can resolve allowed origin per-request instead of baking it at
build time (which produced "Access-Control-Allow-Origin: http://localhost:3000"
with credentials:true in production).
- proxy.ts: per-route CORS policy table covering auth, MCP, form, and
workflow execute endpoints; OPTIONS preflight short-circuit; Vary:
Origin when origin is not '*'; form routes defer to route handler's
addCorsHeaders to avoid double-setting
- next.config.ts: drop all /api/* Access-Control-Allow-* headers; keep
COEP/COOP/CSP
- deployment.ts: addCorsHeaders sets Vary: Origin alongside reflected
Allow-Origin
- Dockerfile: drop NEXT_PUBLIC_APP_URL build placeholder (Zod has
skipValidation:true; build path doesn't read it)
- Remove 8 dead OPTIONS handlers and their preflight tests now that the
proxy handles preflight uniformly
* refactor(cors): consolidate API CORS into proxy as single source of truth
Move CORS for /api/chat/* and /api/form/* into the proxy policy table with
reflected-origin + credentials:false, and delete the per-route addCorsHeaders
helper. Routes no longer set CORS headers — the proxy is the only writer.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(cors): convert proxy CORS policy chain to a rule table + add tests
Replace the if/else chain in resolveApiCorsPolicy with a CORS_RULES table
so each route's policy lives in one place and is trivially scannable.
Add proxy.test.ts covering each rule and the wildcard-with-credentials
invariant.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(cors): scope embed CORS rule to /api/{chat,form}/[identifier] only
The embed policy (reflected origin, credentials:false) was matching
workspace-internal session-authed routes — /api/chat, /api/chat/manage/*,
/api/chat/validate, and the form equivalents — which need the default
credentialed policy. Tighten the matcher to the embed paths only and add
tests covering the exclusion.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(cors): replace embed-path regex with explicit segment check
The regex form `^/api/(chat|form)/(?!manage|validate)[^/]+(/(otp|sso))?$`
was opaque on review and would silently exclude any future identifier
subroute outside the hard-coded (otp|sso) group from the embed policy.
Replace it with an imperative segment check and a named
EMBED_RESERVED_SEGMENTS Set, so the policy boundary is visible at the
top of the function and adding a reserved subpath is a one-line diff.
Add a test asserting that future identifier subroutes also get the
embed policy.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(cors): allow PUT in embed CORS policy for OTP verification
Both /api/chat/[identifier]/otp and /api/form/[identifier]/otp export
PUT for OTP code verification. The embed policy advertised only
GET/POST/OPTIONS, so cross-origin embed clients failed preflight on
verify. Add PUT and assert it in the embed policy test.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent 3930485 commit ef14b2b
26 files changed
Lines changed: 441 additions & 550 deletions
File tree
- apps/sim
- app/api
- chat
- [identifier]
- otp
- sso
- files
- delete
- presigned
- batch
- upload
- form
- [identifier]
- otp
- mcp/copilot
- templates/approved/sanitized
- tools/image
- lib/core/security
- docker
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
| |||
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
53 | | - | |
54 | 52 | | |
55 | 53 | | |
56 | 54 | | |
| |||
69 | 67 | | |
70 | 68 | | |
71 | 69 | | |
72 | | - | |
73 | 70 | | |
74 | 71 | | |
75 | 72 | | |
| |||
131 | 128 | | |
132 | 129 | | |
133 | 130 | | |
134 | | - | |
135 | 131 | | |
136 | 132 | | |
137 | 133 | | |
| |||
248 | 244 | | |
249 | 245 | | |
250 | 246 | | |
251 | | - | |
252 | 247 | | |
253 | 248 | | |
254 | 249 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 55 | + | |
59 | 56 | | |
60 | 57 | | |
61 | 58 | | |
| |||
75 | 72 | | |
76 | 73 | | |
77 | 74 | | |
78 | | - | |
| 75 | + | |
79 | 76 | | |
80 | 77 | | |
81 | 78 | | |
82 | 79 | | |
83 | 80 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 81 | + | |
88 | 82 | | |
89 | 83 | | |
90 | 84 | | |
91 | 85 | | |
92 | 86 | | |
93 | 87 | | |
94 | 88 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 89 | + | |
99 | 90 | | |
100 | 91 | | |
101 | 92 | | |
| |||
114 | 105 | | |
115 | 106 | | |
116 | 107 | | |
117 | | - | |
| 108 | + | |
118 | 109 | | |
119 | 110 | | |
120 | 111 | | |
| |||
135 | 126 | | |
136 | 127 | | |
137 | 128 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 129 | + | |
142 | 130 | | |
143 | 131 | | |
144 | 132 | | |
145 | | - | |
| 133 | + | |
146 | 134 | | |
147 | 135 | | |
148 | | - | |
| 136 | + | |
149 | 137 | | |
150 | 138 | | |
151 | 139 | | |
| |||
158 | 146 | | |
159 | 147 | | |
160 | 148 | | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
| 149 | + | |
165 | 150 | | |
166 | 151 | | |
167 | 152 | | |
| |||
184 | 169 | | |
185 | 170 | | |
186 | 171 | | |
187 | | - | |
| 172 | + | |
188 | 173 | | |
189 | 174 | | |
190 | 175 | | |
191 | 176 | | |
192 | 177 | | |
193 | 178 | | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
| 179 | + | |
198 | 180 | | |
199 | 181 | | |
200 | 182 | | |
201 | 183 | | |
202 | 184 | | |
203 | 185 | | |
204 | 186 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
| 187 | + | |
209 | 188 | | |
210 | 189 | | |
211 | 190 | | |
212 | 191 | | |
213 | 192 | | |
214 | 193 | | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
| 194 | + | |
219 | 195 | | |
220 | | - | |
| 196 | + | |
221 | 197 | | |
222 | 198 | | |
223 | 199 | | |
224 | 200 | | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
236 | 209 | | |
237 | 210 | | |
238 | 211 | | |
239 | 212 | | |
240 | 213 | | |
241 | | - | |
| 214 | + | |
242 | 215 | | |
243 | 216 | | |
244 | 217 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
73 | 71 | | |
74 | 72 | | |
75 | 73 | | |
| |||
81 | 79 | | |
82 | 80 | | |
83 | 81 | | |
84 | | - | |
85 | 82 | | |
86 | 83 | | |
87 | 84 | | |
| |||
181 | 178 | | |
182 | 179 | | |
183 | 180 | | |
184 | | - | |
185 | 181 | | |
186 | 182 | | |
187 | 183 | | |
| |||
0 commit comments