Repository navigation
root: don't fail websocket connections with non-UTF-8 headers - #26688
Merged
BeryJu merged 2 commits intoOct 5, 2026
Merged
Conversation
ChannelsLoggingMiddleware decoded the User-Agent and X-Forwarded-For header values as strict UTF-8. Header values are raw bytes and HTTP doesn't require them to be UTF-8, so a client sending any other byte (for example the Meta AI in-app browser on iOS, whose User-Agent has a Latin-1 non-breaking space, 0xA0) made log() raise UnicodeDecodeError. log() runs before the middleware's try, so the handshake failed with a 500 and the client couldn't open a websocket at all. Decode with errors="backslashreplace": valid UTF-8 is logged as before, and other bytes are logged escaped (\xa0) instead of failing.
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
BeryJu
approved these changes
Oct 5, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #26688 +/- ##
==========================================
+ Coverage 91.76% 92.27% +0.51%
==========================================
Files 1175 1175
Lines 77697 77708 +11
Branches 4129 4129
==========================================
+ Hits 71297 71708 +411
+ Misses 6334 5934 -400
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. |
Contributor
|
|
Contributor
|
|
BeryJu
added a commit
that referenced
this pull request
Oct 7, 2026
…-pick #26688 to version-2026.8) (#26706) * Cherry-pick #26688 to version-2026.8 (with conflicts) This cherry-pick has conflicts that need manual resolution. Original PR: #26688 Original commit: eef0bfd * move test to root/tests/test_ws_client.py Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HPATKAY2JKB2kinG1WrKj4 --------- Co-authored-by: Ryan Pesek <[email protected]> Co-authored-by: Jens Langhammer <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
BeryJu
added a commit
that referenced
this pull request
Oct 7, 2026
…-pick #26688 to version-2026.5) (#26707) * Cherry-pick #26688 to version-2026.5 (with conflicts) This cherry-pick has conflicts that need manual resolution. Original PR: #26688 Original commit: eef0bfd * fix? --------- Co-authored-by: Ryan Pesek <[email protected]> Co-authored-by: Jens Langhammer <[email protected]>
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?
ChannelsLoggingMiddleware.log()now decodes theUser-AgentandX-Forwarded-Forheader values witherrors="backslashreplace"instead of strict UTF-8.ASGI header values are raw bytes, and HTTP doesn't require them to be UTF-8 (RFC 9110 allows
obs-text). When a client sends any other byte,log()raisesUnicodeDecodeError.log()runs before the middleware'stry, so the exception goes up to the ASGI server and the websocket handshake fails with a 500:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 129: invalid start byteWith
backslashreplace, valid UTF-8 is logged as before, and other bytes are logged escaped (Meta\xa0AI), so the log line still shows what the client sent.errors="replace"would also stop the error but loses the byte, andlatin-1would garble valid non-ASCII UTF-8.How was this tested?
Linked issues
None.
AI usage
I used an AI coding assistant to investigate the error, draft the change and its test, and write this description. I reviewed, tested, and edited all of it.
Checklist
make all)make docs)