Skip to content

Commit dfdbe1f

Browse files
authored
Merge pull request #63 from diggerhq/fix/duplicate-cors-headers
Fix duplicate CORS headers on proxied responses
2 parents ec5cf24 + 3235c26 commit dfdbe1f

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)