Skip to content

server/core: relay negotiated websocket subprotocol and stop offering extensions upstream - #25487

Merged
rissson merged 3 commits into
goauthentik:mainfrom
tfahn:fix/rac-websocket-subprotocol-extensions
Aug 26, 2026
Merged

rissson merged 3 commits into
goauthentik:mainfrom
tfahn:fix/rac-websocket-subprotocol-extensions

Conversation

@tfahn

@tfahn tfahn commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Details

What does this PR change?

handle_websocket_upgrade in src/server/core.rs:

  • performs the upstream handshake before answering the client, and names the subprotocol the application selected in the 101
  • removes Sec-WebSocket-Extensions from the handshake it forwards to the application
  • relays the application's response status when it rejects the handshake, instead of switching protocols on a connection that is already gone
  • takes the gunicorn socket path instead of the whole Server (the only field it used), so the handshake can be tested against a stand-in application

The 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 101 never 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 the WebSocket connection ... failed seen in the console.

2. permessage-deflate was negotiated upstream but could not be decoded. Sec-WebSocket-Extensions was not stripped, and every client header was copied into the upstream handshake, so the browser's compression offer reached uvicorn, which appends PerMessageDeflate() unless ws_per_message_deflate is disabled. The negotiated extension was then dropped from the 101 in the same way as the subprotocol, so the upstream leg ran compressed while the browser leg did not. tokio-tungstenite is 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 logs User is not responding about 11 s later, matching the frontend's tunnel.receiveTimeout of 10 s.

The module is identical on main and version-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 accepts permessage-deflate when the handshake offers it. Three of the four tests fail before this change:

  • upgrade_echoes_upstream_subprotocol — the 101 names 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 consumers
  • upgrade_propagates_upstream_rejection — a rejecting application yields its status, not a 101

cargo nextest run --workspace (165 tests), cargo clippy --workspace --all-targets -- -D warnings, cargo +nightly fmt --all --check, cargo deny check and cargo machete all pass.

Protocol level. Comparing ghcr.io/goauthentik/server:2026.8.0 against an image built from version/2026.8.0 plus this change, against the same database, with a raw handshake sent from a socket (no client library in the way):

Handshake 2026.8.0 with this change
offers guacamole + permessage-deflate 101, no subprotocol named 101, names guacamole, no extension
HELLO on a consumer, with a deflate offer no reply ever arrives reply arrives, RSV1 clear
HELLO on a consumer, no deflate offer reply arrives reply arrives
connection denied before accept 101, then silence 403

Asking gunicorn directly on the same image shows the other half: it answers Sec-WebSocket-Protocol: guacamole and Sec-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

  • The project has been linted, built, and tested (make all) (Rust targets, listed above; this change is Rust-only)
  • The documentation has been updated and formatted (make docs)
  • I have read the AI usage policy.

… 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
@tfahn
tfahn requested a review from a team as a code owner August 25, 2026 22:05
@netlify

netlify Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit 1dd9ba5
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a8e8eec84f1310008cadae2
😎 Deploy Preview https://deploy-preview-25487--authentik-integrations.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 1dd9ba5
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a8e8eec08c95900085c7df9
😎 Deploy Preview https://deploy-preview-25487--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@dewi-tik dewi-tik added this to the Release 2026.8.1 milestone Aug 26, 2026
@BeryJu
BeryJu requested a review from rissson August 26, 2026 10:40

@rissson rissson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just removing AI slop, the rest looks fine, especially with new tests

Thanks for the contribution!

Comment thread src/server/core.rs Resolved
Comment thread src/server/core.rs Resolved
Comment thread src/server/core.rs Resolved
Co-authored-by: Marc 'risson' Schmitt <[email protected]>
Signed-off-by: Marc 'risson' Schmitt <[email protected]>
@rissson rissson self-assigned this Aug 26, 2026
@rissson rissson added area:backend backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8 labels Aug 26, 2026
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in authentik Core Aug 26, 2026
@codecov

codecov Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.01299% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.64%. Comparing base (b2a50ac) to head (d3efb55).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
src/server/core.rs 87.01% 16 Missing and 4 partials ⚠️
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     
Flag Coverage Δ
conformance 34.41% <ø> (-0.02%) ⬇️
e2e 39.07% <ø> (-0.02%) ⬇️
integration 30.55% <ø> (-0.46%) ⬇️
rust 42.92% <87.01%> (+2.50%) ⬆️
unit 93.22% <ø> (+<0.01%) ⬆️
unit-migrate 93.24% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@rissson
rissson merged commit 91bdd65 into goauthentik:main Aug 26, 2026
227 of 230 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in authentik Core Aug 26, 2026
@authentik-cherry-pick

Copy link
Copy Markdown
Contributor

🍒 Cherry-pick to version-2026.8 created: #25510

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

SSH via RAC provider fails to connect

3 participants