Skip to content

Reject unsupported extensions in WebSocket client upgrade responses - #1436

Merged
pjfanning merged 1 commit into
apache:mainfrom
He-Pin:fix/ws-reject-unsupported-extension-response
Nov 18, 2026
Merged

pjfanning merged 1 commit into
apache:mainfrom
He-Pin:fix/ws-reject-unsupported-extension-response

Conversation

@He-Pin

@He-Pin He-Pin commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Motivation

Reject only unsolicited negotiated WebSocket extensions without breaking intentionally offered framing-neutral extensions.

Modification

  • Preserve PJ's offered-extension policy from commit 1994e89: compare offered names case-insensitively for typed and raw extraHeaders, and treat a blank response selection as absent.
  • Preserve the original three-argument internal method through forwarding.
  • Add positive handshake and text-echo coverage for typed and raw extension offers.

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

@pjfanning pjfanning added this to the 2.1.0 milestone Nov 13, 2026

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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's Sec-WebSocket-Extensions? That keeps the RFC fix without breaking callers who knowingly negotiate a framing-neutral extension.
  2. Empty header value. The check rejects on the mere presence of a Sec-WebSocket-Extensions header. 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.

He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 17, 2026
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.
@He-Pin
He-Pin force-pushed the fix/ws-reject-unsupported-extension-response branch from 1497985 to 4112a86 Compare November 17, 2026 17:40
pjfanning pushed a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 17, 2026
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.
pjfanning added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 17, 2026
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
@pjfanning
pjfanning force-pushed the fix/ws-reject-unsupported-extension-response branch from 4112a86 to 1994e89 Compare November 17, 2026 18:45
@pjfanning

Copy link
Copy Markdown
Member

I rebased this onto main and pushed a separate commit (1994e89). The handshake now rejects only extensions the client didn't offer (RFC 6455 §4.1 item 5). An extension offered through extraHeaders is accepted when the server selects it (names compared case-insensitively). Unsolicited ones, including permessage-deflate, still fail. Added tests for both cases, kept your empty/whitespace handling, and updated the client docs. Feel free to revert anything you don't agree with.

… 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.
@He-Pin
He-Pin force-pushed the fix/ws-reject-unsupported-extension-response branch from 1994e89 to bfcfe5e Compare November 17, 2026 20:16
@He-Pin
He-Pin requested review from pjfanning and a balanced review from Copilot November 17, 2026 20:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pjfanning
pjfanning merged commit b7ff665 into apache:main Nov 18, 2026
6 checks passed
pjfanning added a commit that referenced this pull request Nov 19, 2026
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
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.

3 participants