Skip to content

Commit 3235c26

Browse files
motatoesclaude
andcommitted
Fix duplicate CORS headers on proxied responses
The API server's CORS middleware adds Access-Control-Allow-Origin: *, and the worker's CORS middleware does the same. When the API proxies worker responses, it forwards all headers including CORS ones via Add(), resulting in duplicate "*, *" which browsers reject. Skip Access-Control-* headers when forwarding proxied responses — the outer server's own CORS middleware already handles these. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fa2b33a commit 3235c26

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

internal/api/dashboard.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,11 @@ func (s *Server) proxyWorkerHTTP(c echo.Context, session *db.SandboxSession, met
10611061
// Forward the worker's response back to the dashboard
10621062
respBody, _ := io.ReadAll(resp.Body)
10631063
for k, vals := range resp.Header {
1064+
// Skip CORS headers — the API server's own CORS middleware adds these,
1065+
// so forwarding them from the worker causes duplicates (*, *).
1066+
if strings.HasPrefix(strings.ToLower(k), "access-control-") {
1067+
continue
1068+
}
10641069
for _, v := range vals {
10651070
c.Response().Header().Add(k, v)
10661071
}

internal/proxy/proxy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ func (r *responseRecorder) WriteHeader(statusCode int) {
302302

303303
func (r *responseRecorder) writeTo(w http.ResponseWriter) {
304304
for k, vals := range r.header {
305+
// Skip CORS headers — the outer server's CORS middleware adds these,
306+
// so forwarding them from the proxied response causes duplicates (*, *).
307+
if strings.HasPrefix(strings.ToLower(k), "access-control-") {
308+
continue
309+
}
305310
for _, v := range vals {
306311
w.Header().Add(k, v)
307312
}

0 commit comments

Comments
 (0)