Skip to content

fix(dial): require exact subprotocol selections - #606

Open
anishpentyala wants to merge 2 commits into
coder:masterfrom
anishpentyala:fix-dial-subprotocol-case
Open

anishpentyala wants to merge 2 commits into
coder:masterfrom
anishpentyala:fix-dial-subprotocol-case

Conversation

@anishpentyala

Copy link
Copy Markdown

Dial accepted a server's selected subprotocol when it differed only by case from an offered value. For example, a client offering Chat accepted chat, even though that exact token was not offered. RFC 7936 section 2 specifies case-sensitive subprotocol matching, and RFC 6455 section 4.1 requires the client to reject a selection it did not offer.

Use exact equality in native client response validation. This intentionally tightens behavior: case-only server selections that previously succeeded now fail the handshake with the existing unexpected-subprotocol error. No selection remains valid, and an exact match anywhere in the offered list still succeeds.

Refs #273 for context. That change preserved the client's spelling in server responses. This PR leaves server-side selection and its existing case-preservation test unchanged. Browser/WASM handshakes still use browser validation. Multiple response protocol fields and token-syntax validation are outside this change.

The new six-case HTTP upgrade integration test covers an exact mixed-case match, a case-only mismatch, a later exact offered match, no selection, an unsolicited selection, and a completely unoffered selection. Successful connections read a binary payload and check Subprotocol; rejected handshakes check the protocol error and nil connection. The test also waits for the upgraded transport to close. Against unchanged production code, only the case-only mismatch assertion fails.

Checked locally:

  • go test -count=1 ./...
  • go test -race -count=1 ./...
  • focused new and existing server-selection tests with -race -count=100
  • go vet ./...
  • tests in internal/examples and internal/thirdparty
  • WASM compilation and the Chrome-backed WASM test suite using the runner pinned in ci/test.sh

Autobahn was not run locally: AUTOBAHN=1 go test -run '^TestAutobahn$' failed during setup because Docker is not installed.

Standards: https://www.rfc-editor.org/rfc/rfc7936#section-2 and https://www.rfc-editor.org/rfc/rfc6455#section-4.1 .

RFC 7936 requires case-sensitive subprotocol matching. Reject server selections that differ only by case from the offered values, while preserving existing server-side negotiation behavior.
Check exact and absent selections, case-only and unsolicited selections, later offered matches, payload reads and upgraded-transport cleanup.

This branch has not been deployed

No deployments
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.

1 participant