Skip to content

[Bug]: Websocket closed on non-lowercase Upgrade #5264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
mattmix opened this issue Jun 14, 2022 · 2 comments
Closed
4 tasks done

[Bug]: Websocket closed on non-lowercase Upgrade #5264

mattmix opened this issue Jun 14, 2022 · 2 comments
Labels
bug Something isn't working triage This issue needs to be triaged by a maintainer

Comments

@mattmix
Copy link

mattmix commented Jun 14, 2022

Is there an existing issue for this?

  • I have searched the existing issues

OS/Web Information

  • Web Browser: N/A
  • Local OS: N/A
  • Remote OS: Rocky 8
  • Remote Architecture: x86_64
  • code-server --version: 4.4.0 b088ec7 with Code 1.66.2

Steps to Reproduce

Working:

curl -v 'http://acn01.agate.msi.umn.edu:46233/?type=Management&reconnectionToken=8d0dc359-d9c0-42bc-92d6-c5e0f8a4f52d&reconnection=false&skipWebSocketFrames=false' -H 'Connection: keep-alive, Upgrade' -H 'Cookie: code-server-session=REMOVED;' -H 'Upgrade: websocket'

Not working:

curl -v 'http://acn01.agate.msi.umn.edu:46233/?type=Management&reconnectionToken=8d0dc359-d9c0-42bc-92d6-c5e0f8a4f52d&reconnection=false&skipWebSocketFrames=false' -H 'Connection: keep-alive, Upgrade' -H 'Cookie: code-server-session=REMOVED;' -H 'Upgrade: WebSocket'

Only difference is the capitalization of the Upgrade header value.

Expected

Should get a HTTP/1.1 101 Switching Protocols response:

*   Trying 10.31.104.175...
* TCP_NODELAY set
* Connected to acn01.agate.msi.umn.edu (10.31.104.175) port 46233 (#0)
> GET /?type=Management&reconnectionToken=8d0dc359-d9c0-42bc-92d6-c5e0f8a4f52d&reconnection=false&skipWebSocketFrames=false HTTP/1.1
> Host: acn01.agate.msi.umn.edu:46233
> User-Agent: curl/7.61.1
> Accept: */*
> Connection: keep-alive, Upgrade
> Cookie: code-server-session=REMOVED;
> Upgrade: websocket
>
< HTTP/1.1 101 Switching Protocols
< Upgrade: websocket
< Connection: Upgrade
< Sec-WebSocket-Accept: gH2cR3x4MfGXKljgIwL3fMYv0sY=
<

Actual

*   Trying 10.31.104.175...
* TCP_NODELAY set
* Connected to acn01.agate.msi.umn.edu (10.31.104.175) port 46233 (#0)
> GET /?type=Management&reconnectionToken=8d0dc359-d9c0-42bc-92d6-c5e0f8a4f52d&reconnection=false&skipWebSocketFrames=false HTTP/1.1
> Host: acn01.agate.msi.umn.edu:46233
> User-Agent: curl/7.61.1
> Accept: */*
> Connection: keep-alive, Upgrade
> Cookie: code-server-session=REMOVED;
> Upgrade: WebSocket
>
* Empty reply from server
* Connection #0 to host acn01.agate.msi.umn.edu left intact

Additional variants such as webSocket and Websocket have the same result.

Logs

I couldn't find any logs related to these events even with --log trace enabled.

Screenshot/Video

No response

Does this issue happen in VS Code or GitHub Codespaces?

  • I cannot reproduce this in VS Code.
  • I cannot reproduce this in GitHub Codespaces.

Are you accessing code-server over HTTPS?

  • I am using HTTPS.

Notes

I am attempting to have code-server sessions launched by our Open OnDemand instance, which uses Apache's mod_lua and mod_proxy_wstunnel to forward connections to jobs running on cluster compute nodes. I'm running into the same issue as others who have setup a proxy front-end to like #4723, but unfortunately the same solution cannot easily be applied in my case because of the dynamic nature of the proxy (configured through mod_lua). Also, I think #5110 might be related, but I'm not sure what CloudFlare's Upgrade string looks like as I don't use it.

mod_proxy_wstunnel is using a hard-coded Camel Case for WebSocket and is replacing the Upgrade: websocket that is received on the frontend from regular browsers. Per the RFC, the Upgrade option should be case insensitive, so this shouldn't matter.

I've checked both the ws and http-proxy npm modules to see if I could find the case sensitive comparison, but I wasn't able to track it down.

I have a temporary fix in place where I've edited the mod_proxy_wstunnel binary so that it sends a lowercase Upgrade: websocket and that has fixed the problem for now, but I'd appreciate if you were able to help me fix it so that code-server could use a case-insensitive Upgrade string.

@mattmix mattmix added bug Something isn't working triage This issue needs to be triaged by a maintainer labels Jun 14, 2022
@robinkar
Copy link

I recently submitted a PR to microsoft/vscode which fixes this issue. So once code-server is updated to use Code 1.68 it will be fixed.

@jsjoeio
Copy link
Contributor

jsjoeio commented Jun 15, 2022

awesome! thanks for letting us know. since this was upstream, i'm going to close this issue.

@jsjoeio jsjoeio closed this as not planned Won't fix, can't repro, duplicate, stale Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage This issue needs to be triaged by a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants