Repository navigation
server: strip hop-by-hop headers before forwarding to the application - #27191
Conversation
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #27191 +/- ##
=======================================
Coverage 92.48% 92.48%
=======================================
Files 1197 1197
Lines 81116 81169 +53
Branches 4497 4550 +53
=======================================
+ Hits 75017 75067 +50
- Misses 6033 6036 +3
Partials 66 66
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Installation instructionsInstructions for docker-composeAdd the following block to your AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-037776ffe58a93728735fe1bcdfc669743565965
# Distroless image: AUTHENTIK_TAG=gh-037776ffe58a93728735fe1bcdfc669743565965-distroless
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)sAfterwards, run the upgrade commands from the latest release notes. Instructions for KubernetesAdd the following block to your authentik:
outposts:
container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
global:
image:
repository: ghcr.io/goauthentik/dev-server
tag: gh-037776ffe58a93728735fe1bcdfc669743565965
# Distroless image: tag: gh-037776ffe58a93728735fe1bcdfc669743565965-distrolessAfterwards, run the upgrade commands from the latest release notes. Playwright e2eDownload this run's HTML report and traces, then open the report: gh run download 40804463183 -D playwright-artifacts
npx playwright show-report playwright-artifacts/playwright-report |
The server passed hop-by-hop headers such as `Connection` through to uvicorn. They describe the client's connection to the server, and RFC 9110 requires proxies to remove them, as the Go server's reverse proxy did. Passing `Connection: Close` on made uvicorn before 0.53 keep the upstream connection open and silently drop the next request sent on it, which uvicorn 0.53 and hyper 1.12 now avoid. Remove them, and the headers `Connection` names, before adding our own forwarding headers. WebSocket upgrades keep them for the handshake.
c2025b0 to
a35f3e6
Compare
# Conflicts: # src/server/core.rs
* main: (114 commits) website/integrations: add planka sso requirement note (#27376) core: bump ruff from 0.17.2 to 0.17.3 (#27370) core: bump cachetools from 7.2.5 to 7.2.6 (#27372) core: bump coverage[toml] from 7.16.2 to 7.17.0 (#27373) core: bump django from 5.2.17 to 5.2.18 (#27369) core: bump google-api-core from 2.36.0 to v2.43.0 (#27214) core: bump boto3 from 1.43.90 to v1.43.119 (#27208) core: bump googleapis-common-protos from 1.75.3 to v1.76.0 (#27217) core: bump msgpack from 1.2.3 to v1.2.4 (#27235) packages/django-dramatiq-postgres: limit task fetching (#27197) web/admin: make flow execute links base-path aware (#27314) lib: fix capture_logs not thread safe (#27355) web/user: keep configure URL query strings when adding next (#27313) web/flow: refresh WebAuthn challenge on authentication retry (#26616) server, lifecycle: drop idle upstream connections before uvicorn does (#27192) outposts: only write changed permissions, add endpoint to rebuild them (#26928) flows: fix planner not resolving stages causing extra queries (#27320) outposts/proxy: honor X-Forwarded-Host in envoy forward auth (#26888) website/docs: Update wording for internal and external users (#27345) server: strip hop-by-hop headers before forwarding to the application (#27191) ...
Details
What does this PR change?
Before the server forwards a request to the application, it now removes the hop-by-hop headers (
Connection,Keep-Alive,Proxy-Connection,Proxy-Authenticate,Proxy-Authorization,TE,Trailer,Transfer-EncodingandUpgrade) and every header thatConnectionnames. It does this before adding its ownHostandX-Forwarded-*headers, so a client can't remove those by naming them inConnection. WebSocket upgrades are unchanged, because the handshake needsConnectionandUpgrade.Why is this change needed?
Hop-by-hop headers describe the client's connection to the server, not the server's connection to the application. RFC 9110 (section 7.6.1) requires proxies to remove them. The Go server's
httputil.ReverseProxydid, but since 2026.8 the Rust server passes them through to uvicorn.That was behind the hang in #27181. uvicorn before 0.53 only treated a lowercase
closeas closing, so a forwardedConnection: Closeleft the upstream connection open while uvicorn discarded the next request sent on it.mainno longer hangs, because of uvicorn 0.53 and hyper 1.12, and #27199 brings both to 2026.8. This PR stops the server from handing the application connection options that were never meant for it, so it doesn't depend on how a given uvicorn or hyper version reacts to them.How was this tested?
Added tests for the header removal, including names listed across several
Connectionheaders.I ran the 2026.8.5 image limited to 0.2 CPU and swapped in a server built from 2026.8.5 with only this change:
Connection: Closefollowed by any request 0, 1 or 1.5 seconds later: the stock server hung on the second request 4 out of 4 times at each delay. With the change, none hung.Connection: Closestraight away, as DokuWiki does: all 4 userinfo calls timed out on the stock server and all 4 succeeded with the change. The flow's WebSocket still connected.Linked issues
refs #27181
Checklist
make all)make docs)