Access-Control-Allow-Origin values sent from proxy destination is concatenated with comma
1. What version of Caddy are you running (caddy -version)?
Caddy 0.9.1
2. What are you trying to do?
I am trying to put Caddy as https frontend to proxy requests to CORS enabled destination server and also to restrict CORS origin to Access-Control-Allow-Origin: "https://client.domain.com".
Since the destination server have CORS support, Caddy retrieves downstream headers as Access-Control-Allow-Origin: "*".
I tried for few hours to omit the destination server's Access-Control-Allow-Origin but Caddy always merges the header value as Access-Control-Allow-Origin: "https://client.domain.com, *" which causes my AJAX uploader to fail with following error:
XMLHttpRequest cannot load.
Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin'
header contains multiple values 'https://client.domain.com, *', but only one is allowed.
Origin 'https://client.domain.com' is therefore not allowed access.
So my question: How could I omit specific header key / value comes from destination server?
3. What is your entire Caddyfile?
0.0.0.0:443
tls ./certs/domain.crt ./certs/domain.key
header / {
Access-Control-Allow-Origin "https://client.domain.com"
Access-Control-Allow-Methods "OPTIONS, HEAD, GET, POST, PUT, DELETE"
Access-Control-Allow-Headers "X-File-Name, X-File-Type, X-File-Size, X-Requested-With"
X-Content-Type-Options "nosniff"
-Server
}
proxy / localhost:8080 {
max_fails 0
proxy_header Host {host}
proxy_header X-Real-IP {remote}
proxy_header X-Forwarded-Proto {scheme}
}
4. How did you run Caddy (give the full command and describe the execution environment)?
caddy -conf Caddyfile
5. What did you expect to see?
Access-Control-Allow-Origin: "https://client.domain.com"
6. What did you see instead (give full error messages and/or log)?
Access-Control-Allow-Origin: "https://client.domain.com, *"
How could I omit specific header key / value comes from destination server?
Use header_downstream -Access-Control-Allow-Origin in your proxy directive. :) See docs.
Also, don't use proxy_header (it is deprecated) - use header_upstream instead.