Repository navigation
server/core: relay negotiated websocket subprotocol and stop offering extensions upstream - #25487
Merged
rissson merged 3 commits intoAug 26, 2026
Conversation
… extensions upstream The websocket bridge answered the handshake with three hardcoded headers and discarded the upstream response, and it answered before connecting upstream, so it could not know what the application had negotiated. Two failures followed. The response never named a subprotocol. RAC is the only consumer that negotiates one and guacamole-common-js offers it, and browsers fail a connection when they offered a subprotocol and the response names none. Connect upstream first and name the selection the application made. Sec-WebSocket-Extensions was forwarded to the application, which accepts permessage-deflate by default, while the response to the client named no extension. The upstream leg then ran compressed and the client leg did not, and tokio-tungstenite is built without deflate support and fails the connection on the first frame with RSV1 set, so the tunnel opened and no data ever reached the client. Drop the offer before forwarding, since the bridge relays frames unchanged and cannot support an extension that alters the framing. Answering after the upstream handshake also means an application that rejects the connection no longer gets a 101 followed by silence; its status is relayed. handle_websocket_upgrade now takes the socket path rather than the whole Server, which is all it used, and which lets the handshake be tested against a stand-in application. Closes goauthentik#25361
✅ Deploy Preview for authentik-integrations ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
rissson
approved these changes
Aug 26, 2026
rissson
left a comment
Member
There was a problem hiding this comment.
just removing AI slop, the rest looks fine, especially with new tests
Thanks for the contribution!
Co-authored-by: Marc 'risson' Schmitt <[email protected]> Signed-off-by: Marc 'risson' Schmitt <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #25487 +/- ##
==========================================
+ Coverage 91.62% 91.64% +0.01%
==========================================
Files 1151 1151
Lines 73251 73412 +161
Branches 3917 4054 +137
==========================================
+ Hits 67118 67276 +158
+ Misses 6097 6094 -3
- Partials 36 42 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Contributor
|
🍒 Cherry-pick to |
rissson
added a commit
that referenced
this pull request
Aug 26, 2026
… extensions upstream (cherry-pick #25487 to version-2026.8) (#25510) Co-authored-by: tfahn <[email protected]> Co-authored-by: Marc 'risson' Schmitt <[email protected]> Co-authored-by: Dewi Roberts <[email protected]> Signed-off-by: Marc 'risson' Schmitt <[email protected]>
1 task
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details
What does this PR change?
handle_websocket_upgradeinsrc/server/core.rs:101Sec-WebSocket-Extensionsfrom the handshake it forwards to the applicationServer(the only field it used), so the handshake can be tested against a stand-in applicationThe frame relay itself is unchanged.
Why is this change needed?
Two separate defects, both in the WebSocket bridge that replaced the Go reverse proxy in #24320 and first shipped in 2026.8.0-rc1. Both are in the core server rather than the RAC outpost, so downgrading the outpost does not help.
1. The
101never named the negotiated subprotocol. The bridge synthesised its own handshake response from three hardcoded headers and discarded the upstream one (let (ws_stream, _) = client_async(...)). It also answered before connecting upstream, so it could not know what the application had selected. RAC is the only consumer that negotiates a subprotocol (authentik/providers/rac/consumer_client.py:65,await self.accept("guacamole")), and guacamole-common-js requests it (new WebSocket(tunnelURL + "?" + data, "guacamole")). Browsers fail a connection when they offered a subprotocol and the response names none, which is theWebSocket connection ... failedseen in the console.2.
permessage-deflatewas negotiated upstream but could not be decoded.Sec-WebSocket-Extensionswas not stripped, and every client header was copied into the upstream handshake, so the browser's compression offer reached uvicorn, which appendsPerMessageDeflate()unlessws_per_message_deflateis disabled. The negotiated extension was then dropped from the101in the same way as the subprotocol, so the upstream leg ran compressed while the browser leg did not.tokio-tungsteniteis built without a deflate feature and rejects the first frame with RSV1 set (ProtocolError::NonZeroReservedBits), which ends the upstream-to-client task. This is the second failure stage: the tunnel opens, the outpost reaches guacd, the session establishes, and then no data reaches the browser until guacd logsUser is not respondingabout 11 s later, matching the frontend'stunnel.receiveTimeoutof 10 s.The module is identical on
mainandversion-2026.8, so the change applies to both.How was this tested?
Unit tests (new, in
mod websockets): a stand-in application on a unix socket answers the handshake the way uvicorn's wsproto implementation does — it names the subprotocol the consumer selected and acceptspermessage-deflatewhen the handshake offers it. Three of the four tests fail before this change:upgrade_echoes_upstream_subprotocol— the101names the selection (defect 1)upgrade_does_not_offer_extensions_upstream— the forwarded handshake carries no extensions (defect 2)upgrade_without_subprotocol_names_none— nothing is named when nothing was negotiated, for the other consumersupgrade_propagates_upstream_rejection— a rejecting application yields its status, not a101cargo nextest run --workspace(165 tests),cargo clippy --workspace --all-targets -- -D warnings,cargo +nightly fmt --all --check,cargo deny checkandcargo macheteall pass.Protocol level. Comparing
ghcr.io/goauthentik/server:2026.8.0against an image built fromversion/2026.8.0plus this change, against the same database, with a raw handshake sent from a socket (no client library in the way):guacamole+permessage-deflate101, no subprotocol named101, namesguacamole, no extensionHELLOon a consumer, with a deflate offerHELLOon a consumer, no deflate offer101, then silence403Asking gunicorn directly on the same image shows the other half: it answers
Sec-WebSocket-Protocol: guacamoleandSec-WebSocket-Extensions: permessage-deflate; client_max_window_bits=15, both of which the bridge discarded.In production. Running the patched server and worker images on 2026.8.0 with the stock RAC outpost, and with the nginx workaround removed: RDP sessions connect and stay usable. The
proxy_set_header Sec-WebSocket-Extensions ""/add_header Sec-WebSocket-Protocol "guacamole"workaround is no longer needed with this change.Linked issues
closes #25361
AI assistance
Disclosed per
AI_POLICY.md: I used Claude Code to help analyse the two failure modes, write this patch and its tests. I reviewed the change, ran the test and lint suites myself, and verified it on my own infrastructure with a real RDP session before opening this PR.Checklist
make all) (Rust targets, listed above; this change is Rust-only)make docs)