Commit Graph

45 Commits

Author SHA1 Message Date
Fabian @ Blax Software ee04c8c731 BF refuse a broken app key or failed app lookup without stopping the server
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>
2026-11-04 12:25:54 +01:00
Fabian @ Blax Software bf3686b973 BF close connections with an unknown app key
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>
2026-11-04 11:56:48 +01:00
Fabian @ Blax Software 093bbe3a44 A tests, documentation for helpers and lifecycle
- 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.
2026-04-02 12:44:16 +02:00
Fabian @ Blax Software 5b8a2a8112 I performance, A testing & event-driven 2026-01-24 13:34:29 +01:00
Blax Software 87bf0ae05e Pusher : -> . 2025-01-18 17:06:52 +01:00
Alexander Blasl 1a5db82c26 Renovation 2025-01-16 08:54:02 +01:00
Marcel Pociot fb958fb851
Merge 2.x changes (#1043)
* Resolve conflicts

* Apply fixes from StyleCI (#1042)
2022-10-06 13:46:54 +02:00
Alex Renoki cbe4378086 Revert "formatting"
This reverts commit 8308a7d16d.
2020-12-07 23:30:36 +02:00
Alex Renoki 8308a7d16d formatting 2020-12-07 20:36:39 +02:00
Alex Renoki e3e2e4a437 wip 2020-09-14 13:25:21 +03:00
Alex Renoki ec47925c71 Added soft closes for connections on SIGTERM/SIGINT 2020-09-12 17:45:07 +03:00
rennokki 341eb9604f
Apply fixes from StyleCI (#518) 2020-09-10 21:59:49 +02:00
Alex Renoki 6f32b89459 wip 2020-09-10 22:59:26 +03:00
Alex Renoki ca4a9a180e Running then() closures as block in tests 2020-09-05 22:40:52 +03:00
rennokki b2ac9090cc
Apply fixes from StyleCI (#503) 2020-09-04 21:28:42 +02:00
Alex Renoki 1e2672d9e0 Updated tests 2020-09-04 22:26:46 +03:00
Alex Renoki e6cfa85472 Replaced blocking Redis instance with non-blocking I/O client 2020-09-04 17:50:49 +03:00
Alex Renoki a45c0bf9cc Using the Redis non-blocking client. 2020-09-04 09:47:23 +03:00
Alex Renoki fadb3fc123 Added redis connection counter. 2020-09-03 16:31:19 +03:00
Alex Renoki ce652bbbcb Mocked message expects array 2020-08-22 20:53:33 +03:00
Alex Renoki 11727e684f Added cors setting outside the app 2020-08-18 16:04:52 +03:00
rennokki aa1c11e149
Merge branch 'master' into redis-replication 2020-08-13 09:59:01 +03:00
Freek Van der Herten fa0bd1c9ef
Apply fixes from StyleCI (#329) 2020-03-04 10:58:39 +01:00
Francis Lavoie db5837831b
Fix test warnings due to usage of deprecated assertArraySubset()
Also changed app_id to strings where appropriate, in real apps they should be strings when read from environment, not ints.
2019-09-23 15:51:43 -04:00
Ahmed Al-Shahawi aecbfeebe7 Add the ability to limit the maximum concurrent connections per appli… (#143)
* Add the ability to limit the maximum concurrent connections per application

Co-Authored-By: AlShahawi <alshahawi@outlook.com>
2019-05-11 08:48:33 +02:00
Marcel Pociot 9ce2cc3ff7
Apply fixes from StyleCI (#3) 2018-12-04 22:22:33 +01:00
freek 279deeeb7c rename client to app 2018-12-01 14:12:15 +01:00
freek e90e86798c renaming clients to apps 2018-12-01 13:57:02 +01:00
Marcel Pociot df4af5f6f9 wip 2018-11-27 21:56:25 +01:00
Marcel Pociot 5b1752201d wip 2018-11-27 21:41:12 +01:00
Marcel Pociot 15aa70d7c9 wip 2018-11-27 21:06:04 +01:00
Marcel Pociot d525cfaa26 wip 2018-11-27 16:43:05 +01:00
freek 636316f1a2 fix namespaces 2018-11-27 16:35:28 +01:00
Marcel Pociot 0bb6a1bba1 wip 2018-11-27 16:07:29 +01:00
Marcel Pociot 86d332a2c0 wip 2018-11-27 15:55:30 +01:00
freek 6895961c74 nitpicks 2018-11-27 00:13:22 +01:00
freek 17109ec8db nitpick 2018-11-26 23:58:28 +01:00
Marcel Pociot f75ed6d86c wip 2018-11-26 00:33:07 +01:00
Marcel Pociot 24580d0e96 wip 2018-11-26 00:29:19 +01:00
Marcel Pociot 420f5271f2 wip 2018-11-26 00:29:07 +01:00
Marcel Pociot 4f5944f9f6 wip 2018-11-26 00:28:57 +01:00
Marcel Pociot 9d7f03d173 wip 2018-11-26 00:20:33 +01:00
Marcel Pociot 1e5b8994df wip 2018-11-26 00:20:18 +01:00
Marcel Pociot fb71f41e05 wip 2018-11-26 00:14:50 +01:00
Marcel Pociot c822ea15a5 wip 2018-11-25 23:43:43 +01:00