Ratchet's router merges the query over the route parameters, so
/app/<anything>?appKey[]=x reached verifyAppKey() (and WebSocketsLogger's
onOpen when logging is on) with an array. QueryParameters::get(): string
threw a TypeError, onOpen only caught WebSocketException and Ratchet's
IoServer only catches \Exception, so the Error left the event loop and the
daemon exited. Anyone could do this before authenticating.
- QueryParameters::get() reads a non-string parameter as '', so the key
becomes an unknown key: websocket.error 4001 and a closed socket.
- onOpen catches any other Throwable, logs it with the trace, sends
websocket.error "Internal server error" (1011) and closes with 1011.
- verifyAppKey() settles the findByKey() promise in place instead of
await(). await() on a pending promise would run the server's own loop
again from a fiber inside onOpen. A rejected lookup is rethrown, a
pending one is refused; the AppManager contract now says findByKey()
must settle synchronously. ConfigAppManager already does.
- A refused connection (4001 unknown key, 4009 origin) closes with that
code instead of 1000. 4000-4099 tells Pusher-style clients not to
reconnect. ConnectionLogger::close() passes the code on.
- The refusal is logged at warning level without a trace, and the
client-supplied key goes into the JSON-encoded context, not the log line.
Tests: the array key with and without the logger, QueryParameters on an
array, an app manager that rejects, one that never settles and one that
throws an Error, the close codes of the 4001/4009 refusals, and the server
test now checks the 4001 close code.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
verifyAppKey() tested the promise from App::findByKey() for truthiness. A
promise object is always truthy, so UnknownAppKey was never thrown and the
then() callback set $connection->app to null. verifyOrigin() then failed
reading a property of null, an ErrorException the onOpen catch did not
cover. The client kept a 101-upgraded socket with no app, got no 4001
frame, was never registered with the channel manager, and onClose later
dereferenced the missing app.
- verifyAppKey() awaits the lookup (React\Async\await; ConfigAppManager
resolves at once) and throws UnknownAppKey for a null result.
- onOpen catches WebSocketException (UnknownAppKey 4001, OriginNotAllowed
4009), sends its websocket.error payload and closes the connection.
- onClose returns early for a connection without an app or socket id.
test_cannot_connect_with_a_wrong_app_key now also waits for the server to
close the socket; new unit tests cover the 4001 and 4009 refusals with
the mock connection.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Introduced `helpers-and-testing.md` to document global helpers and WebsocketService class usage.
- Created `HandlerLifecycleTest.php` to test the full WebSocket handler lifecycle, including connection management, channel subscriptions, and message routing.
- Added `WebsocketServiceTest.php` to validate state tracking methods in WebsocketService, covering user authentication, channel tracking, and broadcast functionality.