The live-sync socket never forgets a closed client, accepts unmasked and unbounded frames, and answers a wrong message with silence #1313
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jaylouisw/packetforge#1313
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The only thing any test asserted about
server/ws.jswas that a broadcast carriesverdicts(#1306). Nobody hadever sent it a frame it did not expect. Four things came out, and the first one is the reason the obvious fix would
not have worked.
1.
clientsonly ever grew — andcloseis never the momentclient.onClosewas never wired and nothing removed a client from the set. Every browser tab that had everconnected stayed in it:
broadcast()wrote to dead sockets for the life of the process andcountnever came down.The trap is that deleting on
socket.on('close')does not fix it. An upgraded socket hasallowHalfOpen = true, so when the peer goes away it emitsendand stops there —closenever fires. Measured:So
endanderrorhave to count as gone as well, or the fix is decorative.2. An unmasked client frame was accepted
RFC 6455 §5.1 makes masking mandatory for client→server frames. It was accepted, so any plain TCP writer could
speak the protocol. A browser always masks, so refusing costs nothing.
3. There was no frame-size ceiling
parseFrame()waits for the length the client declared andBuffer.concat()grows until it arrives. Oneconnection could ask the process to hold as much memory as it liked. An 8 MiB text frame was accepted in full.
Related: the 64-bit length form read
readUInt32BE(6)and ignored the high word, so a declared length over 4 GiBbecame a small frame and the parser then waited for bytes that were never coming.
4. A wrong message was a silence
A client waiting for a board it misspelled could not tell that from an empty board. This is the same rule the HTTP
surface got in #1309: every message gets an answer.
What must be true instead
end,errorandcloseall remove it, and a broadcast reaches only the living;1002; a frame over 1 MiB closes with1009— the code says which rule broke;E_NO_TOPOLOGY(naming the id asked for),E_UNKNOWN_TYPE(naming the one thatexists),
E_BAD_MESSAGE— and none of them closes the connection;