When browsers try to request web socket through wss://xxx/wss, Safari gets a success response of 101 Switching Protocols while Chrome and Firefox both get 502 Bad Gateway.
Did the tunnel return 502 Bad Gateway to Chrome and Firefox? If you set log level to debug, you can see the response headers returned through the tunnel. Perhaps the tunnel didn’t return certain headers to complete the websocket handshake.
The tunnel returns 502 Bad Gateway to Chrome and Firefox but not Safari.
I noticed subtle difference in Sec-Websocket-Extensions:
Working:
Request Headers map[Accept-Encoding:[gzip] Cache-Control:[no-cache] Cdn-Loop:[cloudflare]
Sec-Websocket-Extensions:[x-webkit-deflate-frame]
User-Agent:[Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Safari/605.1.15]
Non-working:
Request Headers map[Accept:[*/*] Accept-Encoding:[gzip] Accept-Language:[en-US,zh-HK;q=0.7,zh-CN;q=0.3] Cache-Control:[no-cache]
Sec-Websocket-Extensions:[permessage-deflate]
User-Agent:[Mozilla/5.0 (Macintosh; Intel Mac OS X 11.1; rv:86.0) Gecko/20100101 Firefox/86.0]
I don’t notice any other difference.
I dsiabled permessage-deflate and disabled Accept-Language. It still doesn’t work.
I found that overlooked this option: Early-Data:[1] It seems to be set by Cloudflare. Requests from Firefox come with this one. Safari doesn’t.
I think the Early-Data flag might be the root cause of my problem. Is it possible to turn it off from Cloudflare?
I turned the flag off by disabling 0-RTT. However it still doesn’t help.
This is so weird and I have no idea what happened. If I don’t use Argo Tunnel but use direct conenction then all browsers work. If I use Argo Tunnel then only Safari works.
Definitely a bug! It seems Argo Tunnel stops processing cookies once it meets CF_Authorization. The cookie sequence depends on the browser. That explains why Safari works but Firefox doesn’t. In Safari, Cloudflare cookies come after the necessary cookies for my site to function. However, in Firefox, Cloudflare cookies come first. When Argo drops rest of my cookies, the request is bad.
Argo Tunnel doesn’t support websocket per message deflate at the moment, and it also doesn’t inspect cookies, so they should all be forward to your origin. Does Nginx expect cookies in a certain order?
Hi I’ve finally resolved the issue. It’s not a bug of cloudflared. The problem is that I passed the huge JWT token and Authorization cookies to the upstream, which is unnecessary and in this case, causes a corrupted header. After striping away all the headers set by cloudflare, the problem resolved.