Repository navigation
Reject unsupported extensions in WebSocket client upgrade responses - #1436
Conversation
pjfanning
left a comment
There was a problem hiding this comment.
Thanks. Failing at the handshake is clearer than what happens today: with permessage-deflate selected, the connection opens and then dies on the first compressed frame, because the client FrameHandler treats any RSV bit as a protocol error. Two points:
- Extensions offered through
extraHeaders. RFC 6455 §4.1 item 5 only requires failing when the server selects an extension the client did not request. When the caller offered it explicitly, today's behaviour works for any extension that doesn't use RSV bits, since frames pass through unchanged. Rejecting those too turns a working setup into a handshake failure, and you call that out as an implementation-capability restriction rather than an RFC requirement. Could the check reject only extensions that weren't in the request'sSec-WebSocket-Extensions? That keeps the RFC fix without breaking callers who knowingly negotiate a framing-neutral extension. - Empty header value. The check rejects on the mere presence of a
Sec-WebSocket-Extensionsheader. Some servers send it with an empty value when nothing was selected. Treating an empty or whitespace-only value as "no extension" would avoid failing those handshakes for no reason.
Motivation: The client should not silently accept an unsupported selected extension. An empty response header, however, does not select an extension and should not prevent an otherwise ordinary WebSocket connection. Modification: Retain the existing nonempty extension selection check. Treat an empty or HTTP-OWS-only response header as no selection. Add positive handshake and text-echo tests for both forms, and document the distinction. Result: Blank extension response headers allow ordinary WebSocket exchanges. Nonempty selection handling is unchanged by this follow-up. PJ's separate request to preserve explicitly offered framing-neutral extensions remains an unresolved API-policy question; this is not a complete review resolution. Tests: - Offline Scala 2.13.18 compilation of changed Handshake.scala and WebSocketClientSpec.scala against cached existing module classes: passed. - Direct ScalaTest WebSocketClientSpec, filtered to "extension response value": 2 positive tests passed using those compiled classes and cached dependencies. This is not a clean full-project build or Scala 3 result. - Cached official scalafmt 3.11.5 applied to the two changed Scala files. - git diff --check: passed. - Full suite, MiMa, docs/paradox and CI were not run for this revision. References: Refs apache#1436 and PJ Fanning review 5938857123. RFC 6455 section 4.1 item 5. Original investigation: netty/netty#18322.
1497985 to
4112a86
Compare
Motivation: The client should not silently accept an unsupported selected extension. An empty response header, however, does not select an extension and should not prevent an otherwise ordinary WebSocket connection. Modification: Retain the existing nonempty extension selection check. Treat an empty or HTTP-OWS-only response header as no selection. Add positive handshake and text-echo tests for both forms, and document the distinction. Result: Blank extension response headers allow ordinary WebSocket exchanges. Nonempty selection handling is unchanged by this follow-up. PJ's separate request to preserve explicitly offered framing-neutral extensions remains an unresolved API-policy question; this is not a complete review resolution. Tests: - Offline Scala 2.13.18 compilation of changed Handshake.scala and WebSocketClientSpec.scala against cached existing module classes: passed. - Direct ScalaTest WebSocketClientSpec, filtered to "extension response value": 2 positive tests passed using those compiled classes and cached dependencies. This is not a clean full-project build or Scala 3 result. - Cached official scalafmt 3.11.5 applied to the two changed Scala files. - git diff --check: passed. - Full suite, MiMa, docs/paradox and CI were not run for this revision. References: Refs apache#1436 and PJ Fanning review 5938857123. RFC 6455 section 4.1 item 5. Original investigation: netty/netty#18322.
Motivation: RFC 6455 section 4.1 item 5 requires failing the handshake when the server selects an extension the client did not request. The change also rejected extensions the caller offered explicitly through extraHeaders, which used to work for extensions that don't change the framing. Modification: Collect the extension names offered in the request's Sec-WebSocket-Extensions headers and reject only selected extensions that are not among them (names compared case-insensitively). Add tests for an offered extension being accepted and for a different one being rejected, and update the client WebSocket docs. Result: Unsolicited extensions, including permessage-deflate, still fail the handshake; extensions the caller deliberately negotiated keep working. Tests: - sbt "http-core/testOnly ...WebSocketClientSpec": 24 passed - sbt "http-core/mimaReportBinaryIssues": passed References: Refs apache#1436 review
4112a86 to
1994e89
Compare
|
I rebased this onto |
… compatibility Motivation: WebSocket responses should only select extensions offered by the client. Empty extension values select nothing, and existing framing-neutral extension users must retain their working handshake behavior. Modification: Preserve PJ Fanning's offered-extension name comparison, client wiring, documentation and normal negotiation coverage. Ignore empty extension values. Retain the original three-argument internal validateResponse entry point with a forwarding overload. Exercise both raw and typed ordinary extension offers. Result: Explicitly offered extensions and empty selections keep working without implementing client compression. The original internal JVM call remains valid. Tests: - Offline Scala 2.13.18 changed production/spec compile with -Werror: passed. - Four selected ordinary handshake/text-echo cases: passed against cached dependencies. - Caller compiled against exact main's old three-argument method: fails with NoSuchMethodError on PJ's previous head and passes with this overload. - Cached scalafmt 3.11.5 and git diff --check: passed. - Full sbt build, cross-Scala tests and aggregate MiMa: not run in this environment. References: Refs apache#1436. Preserves PJ Fanning's contribution in commit 1994e89.
1994e89 to
bfcfe5e
Compare
Motivation: Several recently merged PRs left review points unaddressed: docs that were asked to be dropped, comments and tests that were suggested, and small API and internal tidy-ups. Modification: - Add a Scala FilenameEncoding alias and values to Multipart.FormData and use them in the Scala toEntity signature and tests (#1494). - Render the form-data Content-Disposition header directly instead of rendering it twice and slicing off the prefix (#1494). - Drop the docs paragraph about unpaired URI surrogates (#1426) and the cookie -0000 sentence in request-level.md (#1493). - Fix the javadsl Multipart.FormData doc the same way #1483 fixed the scaladsl one. - Comment the cookie date rule copies so they stay in sync (#1458). - Test custom methods starting with Q next to the QUERY fast path (#1477). - Use one root package import and a dilated timeout in HeaderCompressionSpec (#1438). - Pass isTrailer to HttpMessageRendering.renderHeaders explicitly (#1463). - Remove the unused forwarding overloads in Handshake.Client and EnabledPingState (#1436, #1462). - Move the media type model checks from the routing spec to a new http-core MediaTypesSpec (#1437, #1454). - Hash the WebSocket key without String.valueOf (#1439). Result: The review points are addressed. The only public API change is the added Scala FilenameEncoding alias. Tests: - http-core/testOnly MultipartSpec MultipartsSpec MediaTypesSpec RequestParserCRLFSpec RequestParserLFSpec HeaderCompressionSpec WebSocketClientSpec HeaderSpec HttpHeaderSpec: 314 passed - http2-tests/testOnly HttpMessageRenderingSpec Http2PingSchedulingSpec: 38 passed - http-tests/testOnly FileAndResourceDirectivesSpec: 63 passed - http-core/mimaReportBinaryIssues: passed References: Refs #1426, #1436, #1437, #1438, #1439, #1454, #1458, #1462, #1463, #1477, #1483, #1493, #1494
Motivation
Reject only unsolicited negotiated WebSocket extensions without breaking intentionally offered framing-neutral extensions.
Modification
Result
Unsolicited extensions are rejected while supported handshakes remain unchanged. Offering an extension does not install a codec; the client still does not implement compression.
Tests
Four focused handshake and text-echo cases passed, with strict cached Scala 2.13 compilation. A precompiled caller check confirmed that forwarding restores the old JVM method descriptor. Scalafmt and diff checks passed. Full CI for this exact head is queued; no full-suite success is claimed.
References