Repository navigation
fix(mqtt): scope wildcard subscriptions and reserved user topics - #14030
Conversation
Refuse a wildcard first level (# or +) at SUBSCRIBE, as users/ wildcards already are, and deliver the reserved users/<id> topic only to that user's connections. Wildcards below the first level are unaffected.
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
🟢 Tier S · Ready to mergeThe pull request rejects MQTT subscription filters with a wildcard first level and restricts delivery on reserved Latest changes: The newest commits add named broker, transport, and pub/sub fakes plus unit regressions for owner-only delivery, owner wildcard delivery, and ordinary-topic fan-out.
📂 Walkthrough · 6
Reviewed the commits since |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…talled The e2e outcome test can no longer reach deliver()'s ownership check once SUBSCRIBE refuses first-level wildcards, since the broker only installs granted filters. Drive Utopia\Mqtt\Server through an in-process adapter with a handler that grants every filter, then assert what Handler::deliver() sends to each connection.
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
What does this PR do?
Tightens topic scoping on the MQTT push broker (
src/Appwrite/Mqtt/Handler.php):#,+,+/…) gets SUBACK0x80, the same asusers/wildcards already do. Wildcards below the first level, such asscores/+/live, are still granted.users/<id>topic goes only to connections whose identity is<id>, whatever filter matched. A deeperusers/<id>/…path stays an ordinary topic, asdeniesUserTopic()already treated it.Behaviour change: a client can no longer subscribe to a first-level wildcard on the push broker. It gets
0x80for that filter, and its other filters are unaffected.Test Plan
tests/e2e/Services/Mqtt/MqttServerTest.php:testUserTopicOwnershipOnSubscribenow also expects0x80for#,+,+/+,+/#and+/<otherId>.testUserTargetedPushReachesOnlyItsUsersends a users-addressed push and checks that only that user receives it, whatever filters other connections in the project hold.tests/unit/Mqtt/HandlerTest.php(new): once SUBSCRIBE refuses these filters, no E2E test can reach the ownership check indeliver(), because the broker only installs granted filters. This test drivesUtopia\Mqtt\Serverthrough an in-process adapter with a broker handler that grants every filter, which stands in for a subscription the gate didn't catch. It then asserts whatHandler::deliver()sends to each connection:users/<id>reaches only its owner, even though other users hold#,+/+and+/<id>.users/<id>/…path, still fan out to wildcards.With the ownership check removed from
deliver(),testUserTopicReachesOnlyItsOwnerfails.I ran the MQTT E2E group against a local stack, with the broker carrying each version of
Handler.php:…OwnershipOnSubscribe…ReachesOnlyItsUserWith this PR,
MqttServerTestpassed 25/25 in two whole-file runs. One earlier run stalled on the last test (testCleanStartDiscardsSession); that test passed on its own and in both later runs, and I couldn't reproduce the stall. Pint and PHPStan pass on the changed files.Related PRs and Issues
Checklist