Skip to content

Close the connection when the WebSocket handshake fails - #406

Merged
taylorotwell merged 1 commit into
laravel:mainfrom
boutetnico:close-connection-on-failed-handshake
Sep 10, 2026
Merged

taylorotwell merged 1 commit into
laravel:mainfrom
boutetnico:close-connection-on-failed-handshake

Conversation

@boutetnico

Copy link
Copy Markdown
Contributor

When ServerNegotiator rejects a handshake it returns the appropriate response — 400 for an invalid Sec-WebSocket-Key, 426 for an unsupported Sec-WebSocket-Version — but attemptUpgrade() writes that response and returns a ReverbConnection regardless of its status. The connection is never closed, and dispatch() then invokes the controller with a connection that was never upgraded.

A client sending a malformed handshake therefore receives a response that never terminates. A strict HTTP client waits until it times out; curl reports the status and exits, leaving the connection held open on the server. Repeated by a scanner, these accumulate.

This closes the connection and returns null when the negotiator's status is not 101, so dispatch() stops before reaching the controller.

The two added tests cover the invalid key and unsupported version paths. Both fail against main.

@boutetnico
boutetnico marked this pull request as draft September 10, 2026 08:58
@boutetnico boutetnico closed this Sep 10, 2026
@boutetnico boutetnico reopened this Sep 10, 2026
@boutetnico
boutetnico marked this pull request as ready for review September 10, 2026 09:02
@taylorotwell
taylorotwell merged commit dbcb96d into laravel:main Sep 10, 2026
49 of 54 checks passed
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.

2 participants