Skip to content

fix(realtime): address account events by the full user id - #15308

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/realtime-dotted-user-id
Nov 4, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/realtime-dotted-user-id

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

What

Realtime::fromPayload() derived the account.<userId> channel and the user:<userId> role for user events by splitting the event name on . and taking parts[1]. Custom user ids may contain dots, so an event about user john.doe (users.john.doe.sessions.…) was addressed to channel account.john and role user:john.

Effect: a subscriber whose own id is john and who subscribes to the default account channel received john.doe's account events — including the user profile payload — while john.doe received none of their own. The same name-split also mis-computed the event suffix used to decide whether access changed.

Fix

The authoritative user id is already carried as the event's userId param (it is passed to realtime->send() for exactly this flow). Thread it into fromPayload() and use it for the account channel, the user role and the suffix split, keeping parts[1] only as a fallback when no id is supplied. The teams.memberships.delete branch already uses the payload's userId over the split name — same principle.

Finding

Strix #16 (medium, CVSS 4.3). Realtime account events addressed to a truncated user id.

Test

Added testFromPayloadKeepsDottedUserIdIntact to the existing MessagingTest (which already unit-covers fromPayload): a john.doe id keeps account.john.doe / user:john.doe and never emits the truncated account.john / user:john. All 70 MessagingTest cases pass; lint and analyze pass.

Part of appwrite-labs/infrastructure#1013

fromPayload derived the account channel and user role from the split
event name, so a custom user id containing a dot (e.g. john.doe) was
truncated to the part before it (john). Account events then went to
account.john / user:john, delivering one user's account events to a
different user and starving the real owner of its own.

Thread the authoritative userId (already carried as the event's userId
param) into fromPayload and use it for the channel, the role and the
suffix split, instead of parts[1].
@luxor-code-review

luxor-code-review Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to

🟡 Medium — Dotted userId still breaks account.{action} augmentation · Realtime.php:1279–1285 · unchanged line

// src/Appwrite/Messaging/Adapter/Realtime.php
1279	        if (
1280	            $action !== null
1281	            && $parts[0] === 'users'
1282	            && ($parts[2] ?? null) !== $action
1283	        ) {
1284	            $action = null;
1285	        }

The users branch now routes dotted user ids correctly for channels, roles, and suffix extraction, but the action-augmentation guard still splits the event by dots: ($parts[2] ?? null) !== $action at src/Appwrite/Messaging/Adapter/Realtime.php:1282. For users.john.doe.create the dot-split makes parts[2] = 'doe', so the guard nulls the action and the unscoped account.create channel is never appended. Guest subscriptions to account.{action} (documented in tests/unit/Messaging/MessagingTest.php:466-471) therefore miss top-level user events for any user whose custom id contains a dot — the exact population this PR aims to support.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 No tests for userId absent/non-dotted fallback paths (MessagingTest.php:1401) — The only new test (tests/unit/Messaging/MessagingTest.php:1381) covers the dotted-id-with-param happy path.

The change makes the realtime messaging adapter resolve user identity from an explicit userId parameter instead of inferring it by splitting the event name on dots, which previously corrupted roles and suffixes for dotted custom ids.

Files Change
src/Appwrite/Event/Realtime.php Publisher now forwards the event's userId param as the new userId argument to fromPayload.
src/Appwrite/Messaging/Adapter/Realtime.php fromPayload accepts an optional ?string $userId; the users branch uses it to derive Role::user(Id::custom($userId)), and computes the event suffix via prefix stripping (str_starts_with + substr) instead of array_slice($parts, 2), keeping dotted ids intact.
tests/unit/Messaging/MessagingTest.php Adds testFromPayloadKeepsDottedUserIdIntact asserting channels, role, and permissionsChanged for a dotted user id passed explicitly.

Reviewed commit: e55e4d1

@appwrite

appwrite Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Realtime user events now use the event’s full userId for account channels and user roles, and parse event suffixes after that ID so dotted IDs remain intact. The action-channel logic also preserves top-level action filters for dotted IDs, with regression coverage for both account routing and action channels.

Latest changes: The new commits use the parsed user-event suffix for the top-level action guard and suffix account channels regardless of how many dot-separated segments the user ID contains, with a regression assertion for dotted-ID create channels.

Verdict New comments Fixed Still open
✅ Approved 0 1 0
📂 Walkthrough · 3
File Change
src/Appwrite/Event/Realtime.php Passes the event userId into realtime payload routing.
src/Appwrite/Messaging/Adapter/Realtime.php Uses the full user ID for account channels and roles, parses the suffix after that ID, and preserves action channels for dotted IDs.
tests/unit/Messaging/MessagingTest.php Covers dotted user IDs in account routing, permissions handling, and top-level action channels.
✅ Fixed since the last review · 1
  • Preserve action-channel suffixes for dotted user IDs · src/Appwrite/Messaging/Adapter/Realtime.php:1090

Reviewed the commits since e55e4d1 · Details · Comment @appwrite review to re-run, or mention @appwrite with a question.

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · See the inline comments. Summary

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

The top-level-user-event check keyed off parts[2], and the action-channel
augmentation off leaf/parent adjacency, both of which a dotted user id
shifts. Use the parsed suffix for the top-level check and treat any
account.* channel as action-suffixable, so users.john.doe.create emits
account.create and account.john.doe.create. Covered in the e2e-adjacent
MessagingTest.
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/realtime-dotted-user-id (after).

Metric Before After Change
🚀 Requests/sec 185.17 209.13 🟢 +12.9%
⏱️ Latency P50 93.05 ms 82.04 ms 🟢 -11.8%
⏱️ Latency P95 214.55 ms 195.28 ms 🟢 -9%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 82.04 195.28 13,053 209.13 -19.27
Account 149.7 285.51 687 11.42 -31.05
TablesDB 78.29 138.73 7,099 116.4 -39.05
Storage 78.37 176.91 3,435 58.1 -12
Functions 120.87 244.2 1,832 31.7 +1.8

Top API waits (after)

API request Max wait (ms)
account.prefs.update 474.16
tablesdb.rows.create 455.9
account.name.update 444.92
storage.buckets.create 430.71
functions.create 403.32

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@ChiragAgg5k
ChiragAgg5k merged commit 8cda7d5 into main Nov 4, 2026
70 checks passed
@ChiragAgg5k ChiragAgg5k self-assigned this Nov 5, 2026
ChiragAgg5k added a commit that referenced this pull request Nov 12, 2026
fix(realtime): address account events by the full user id

(cherry picked from commit 8cda7d5)
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.

1 participant