Skip to content

server: strip hop-by-hop headers before forwarding to the application - #27191

Merged
dominic-r merged 2 commits into
mainfrom
dominic/server-strip-hop-by-hop-headers
Oct 29, 2026
Merged

dominic-r merged 2 commits into
mainfrom
dominic/server-strip-hop-by-hop-headers

Conversation

@dominic-r

@dominic-r dominic-r commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

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-Encoding and Upgrade) and every header that Connection names. It does this before adding its own Host and X-Forwarded-* headers, so a client can't remove those by naming them in Connection. WebSocket upgrades are unchanged, because the handshake needs Connection and Upgrade.

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.ReverseProxy did, 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 close as closing, so a forwarded Connection: Close left the upstream connection open while uvicorn discarded the next request sent on it. main no 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 Connection headers.

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:

  • A request with Connection: Close followed 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.
  • A real login in Chromium, with a callback server that exchanges the code and calls userinfo with Connection: Close straight 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.
  • A chunked POST to the token endpoint still reached Django with its body.

Linked issues

refs #27181


Checklist

  • The project has been linted, built, and tested (make all)
  • The documentation has been updated and formatted (make docs)
  • I have read the AI usage policy.

@dominic-r
dominic-r requested a review from a team as a code owner October 26, 2026 15:39
@dominic-r dominic-r added area:backend backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8 labels Oct 26, 2026
@dominic-r dominic-r self-assigned this Oct 26, 2026
@netlify

netlify Bot commented Oct 26, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit c2025b0
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6adf7439f6034200b9ce3ecc
😎 Deploy Preview https://deploy-preview-27191--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.

@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.74074% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.48%. Comparing base (98c4b28) to head (037776f).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/server/core.rs 90.74% 5 Missing ⚠️
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           
Flag Coverage Δ
conformance 31.15% <ø> (+<0.01%) ⬆️
e2e 36.01% <ø> (+<0.01%) ⬆️
integration 28.62% <ø> (+<0.01%) ⬆️
rust 46.52% <90.74%> (+0.54%) ⬆️
unit 94.13% <ø> (+<0.01%) ⬆️
unit-migrate 94.12% <ø> (+<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.

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Installation instructions

Instructions for docker-compose

Add the following block to your .env file:

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)s

Afterwards, run the upgrade commands from the latest release notes.

Instructions for Kubernetes

Add the following block to your values.yml file:

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-distroless

Afterwards, run the upgrade commands from the latest release notes.

Playwright e2e

Download 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.
@dominic-r
dominic-r force-pushed the dominic/server-strip-hop-by-hop-headers branch from c2025b0 to a35f3e6 Compare October 26, 2026 17:38
@dominic-r dominic-r removed the backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8 label Oct 26, 2026
# Conflicts:
#	src/server/core.rs
@dominic-r
dominic-r merged commit 2c34c1e into main Oct 29, 2026
170 of 171 checks passed
@dominic-r
dominic-r deleted the dominic/server-strip-hop-by-hop-headers branch October 29, 2026 15:35
kensternberg-authentik added a commit that referenced this pull request Oct 30, 2026
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants