Repository navigation
Fix two crashes in Socket.Web on frames the RFC allows - #6
Merged
dominicletz merged 2 commits intoNov 2, 2026
Merged
Conversation
send/3 and close/3 both take a `mask:` option, and `mask: false` is how a caller says "send this frame unmasked" — a server must not mask, per RFC 6455 §5.3. forge/2 only knew `nil` and an integer key, so `false` fell into the key clause and reached Bitwise.bxor/2: a legal call raised ArithmeticError. The new test file also carries the harness. The listener is bound in the test process before the server task starts, so a client can never dial a port nobody is listening on yet.
RFC 6455 §7.4.2 leaves the range 3000-4999 to applications and libraries. close_code/1 only knew the registered set, and it is used on both sides of the wire: closing with 4000 raised FunctionClauseError, and so did reading a peer's clean close carrying such a code — a crash of the reader on a well-behaved connection.
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.
Two small fixes in
lib/socket/web.ex, each with a test that fails without it.Both are crashes on input a well-behaved peer, or a caller reading the docs, can
produce.
forge/2now treatsfalseas "do not mask".send/3andclose/3document a
mask:option, andmask: falseis how a caller says the framegoes out unmasked — which RFC 6455 §5.3 requires of a server.
forge/2onlyhad a clause for
niland one for an integer key, sofalsefell into thekey clause and reached
Bitwise.bxor/2:Socket.Web.send!(socket, {:text, "x"}, mask: false)raisedArithmeticError.close_code/1now accepts any integer code. RFC 6455 §7.4.2 leaves3000-4999 to applications and libraries. The function is used on both sides of
the wire:
Socket.Web.close(socket, {4000, "bye"})raisedFunctionClauseError, and so did reading a peer's clean close carrying such acode — which kills the reader on a healthy connection.
Added
test/web_test.exs, the first test file forSocket.Web: a harness thatbinds the listener before starting the server task, and five tests covering a
binary round trip, an unmasked send, a fragmented message, an application close
code and a registered one.
Verified on Elixir 1.18.3 / OTP 26:
mix format --check-formattedpasses,mix testis 16 tests / 0 failures.mix compile --warnings-as-errorsstillfails on this branch, with exactly the warnings
masteralready has — the samenine, at the same sites, shifted by the four lines added here. Nothing new.