Skip to content

websocket: Fix uncaught exception in extension parsing - #3940

Merged
bdarnell merged 2 commits into
tornadoweb:masterfrom
bdarnell:claude/project-thread-oc50jn
Nov 27, 2026
Merged

bdarnell merged 2 commits into
tornadoweb:masterfrom
bdarnell:claude/project-thread-oc50jn

Conversation

@bdarnell

Copy link
Copy Markdown
Member

No description provided.

accept_connection handles ValueError from _accept_connection by calling
_abort(), but before the stream is detached that fails with
AttributeError in close(), producing a 500 and a logged traceback. One
way to reach it is a permessage-deflate parameter in RFC 2231 form whose
decoded value contains a newline: it is echoed in
Sec-WebSocket-Extensions and set_header rejects it.

Now a ValueError before the upgrade sends a 400 response.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VamvWqd4dUJoMCufE5qJ3G
RFC 7692 section 5 requires the server to decline an offer with an
invalid parameter value. _create_compressors only rejected unknown
parameter names and window sizes that int() can't parse, so values like
"+15", "1_5", "15\n" (via RFC 2231 encoding) and a value on
*_no_context_takeover were accepted and echoed back in the response.
A value containing a newline then failed in set_header, producing a 500.

Now the no_context_takeover parameters must have no value and the
max_window_bits values must be ASCII digits; anything else declines the
offer (and, on the client, fails the connection, as the RFC also
requires).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VamvWqd4dUJoMCufE5qJ3G
@bdarnell
bdarnell merged commit dbaa6c5 into tornadoweb:master Nov 27, 2026
23 checks passed
@bdarnell
bdarnell deleted the claude/project-thread-oc50jn branch November 27, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants