Skip to content

fix(realtime): apply membership privacy to membership events (appwrite:appwrite:alert#4390) - #15176

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix-membership-realtime-privacy
Nov 11, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix-membership-realtime-privacy

Conversation

@claudear

@claudear claudear commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes code-scanning alert appwrite:appwrite:alert#4390 — Membership realtime events disclose fields hidden by membership privacy settings.

A membership event (teams.[teamId].memberships.[membershipId].create / .update / .delete) is addressed to the single role team:{teamId}, which every confirmed member holds, and the payload it carries is the HTTP response rendered for the writing caller:

  • Memberships/Create.php and Memberships/Update.php render userName / userEmail behind $isVisible (privileged ‖ API key ‖ self), so an API key or admin-mode write — the normal server-SDK way to add someone to a team — renders the member's real name and email.
  • Neither action applies the membershipsUserId policy at all, so userId is always present.
  • app/controllers/shared/api.php copies that response into the event, Realtime::from() forwards it, and Realtime::getRealtimePayload() stripped only keys explicitly marked sensitive — of which these routes set none.
  • Realtime/Event/Handler.php serializes the payload once and sends identical bytes to every receiver, so there is no recipient-specific filtering anywhere downstream.

Net effect: in a project with membership privacy on (and all memberships* flags default to false, i.e. hidden, for newly created projects), an ordinary member holding an open memberships / teams.<id> subscription received exactly the fields GET /teams/:teamId/memberships[/:membershipId] deliberately withholds. No elevated scope needed.

The fix

Appwrite\Event\Realtime::getRealtimePayload() now also drops the membership fields the project's privacy policy hides, applied with no privileged or self exemption — the broadcast is one payload for the whole team, so it is reduced to what the least privileged member may read. The defaults mirror the read endpoints (true for name/email/phone/id/MFA so existing projects keep today's behaviour, false for userAccessedAt).

Doing it at this single chokepoint covers every membership write — create, role update, invite acceptance (Memberships/Status/Update.php) and delete — instead of four per-action payload declarations.

Unchanged:

  • HTTP responses — the writer still gets what they are entitled to see.
  • Webhooks and function events — they read payload directly, not getRealtimePayload(), and are configured by the project owner.
  • Event routing — RealtimeAdapter::fromPayload() still receives the full payload, so the delete event's extra user:{userId} addressing (which lets the removed member receive it) keeps working.
  • Console organizations — app/config/console.php sets every membership privacy flag to true, so console membership events are untouched.

Test Plan

TDD: tests/unit/Event/RealtimeTest.php gained testMembershipPayloadDropsFieldsHiddenByPrivacyPolicy, which failed on the pre-fix code with Failed asserting that an array does not have the key 'userName' and passes after, plus testMembershipPayloadKeepsFieldsAllowedByPrivacyPolicy pinning that a project which allows the fields keeps broadcasting them.

End-to-end, RealtimeCustomClientTest::testChannelMembershipsPrivacy has an ordinary confirmed member listening on memberships while an API key adds a second user: the key's HTTP response carries the new member's id, name and email, and the event the teammate receives carries none of them, for both the create and the role update.

docker compose exec appwrite test tests/unit/Event/RealtimeTest.php
docker compose exec appwrite test tests/e2e/Services/Realtime --filter=testChannelMembershipsPrivacy

Unit suite: 2458 tests, the only errors are the pre-existing Auth\KeyTest (no JWT signing key) and Databases\ListCacheTest (no Redis) environment failures. composer lint and phpstan clean on the changed files.

Related PRs and Issues

Have you read the Contributing Guidelines on issues?

Yes.

🤖 Generated with Claude Code

A membership event is addressed to team:{teamId}, which every confirmed
member holds, while its payload is the HTTP response rendered for the
writing caller — an API key or an admin-mode caller renders the member's
real name and email. The realtime payload only dropped keys explicitly
marked sensitive, so a project with membership privacy enabled still
broadcast the member's id (always) and their name, email, phone and MFA
status (whenever the writer was privileged) to the whole team.

Apply the project's membership privacy policy when building the realtime
payload, with no privileged or self exemption, so the single payload every
member receives carries only what the least privileged of them may read.
The HTTP response, webhooks and function events are unchanged.

Co-Authored-By: Claude Opus 5 <[email protected]>
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR adds privacy handling for team membership realtime events, mirroring the existing memberships privacy configuration used by the HTTP API, and covers the new behavior with unit and e2e tests.

Files Change
src/Appwrite/Event/Realtime.php Detects membership event labels and builds a privacy-filtered realtime payload per the project's membership privacy settings.
tests/e2e/Services/Realtime/RealtimeCustomClientTest.php Adds e2e coverage for redacted membership events on the custom-client realtime channel.
tests/unit/Event/RealtimeTest.php Adds unit tests for the membership privacy payload logic.

Reviewed commit: 1202ab9

@ghost

ghost commented Nov 2, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Membership realtime payloads now apply project privacy settings to fields that team members are not allowed to see, while preserving full payloads for routing and HTTP responses. Unit and end-to-end tests cover hidden and allowed fields for membership events. The latest commit corrects the test helper’s array-shape annotation for its literal $id key.

Latest changes: The new commit quotes $id in the helper’s array-shape return annotation so it matches the returned array key.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 3
File Change
src/Appwrite/Event/Realtime.php Filters membership fields hidden by the project privacy settings from realtime event payloads.
tests/unit/Event/RealtimeTest.php Tests filtering of hidden membership fields and retention of fields allowed by policy.
tests/e2e/Services/Realtime/RealtimeCustomClientTest.php Tests that create and role-update membership events hide private fields from an ordinary team subscriber; the latest commit corrects the helper’s $id array-shape annotation.

Reviewed the commits since 1202ab9 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost 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

@github-actions

github-actions Bot commented Nov 2, 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.

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-membership-realtime-privacy (after).

Metric Before After Change
🚀 Requests/sec 198.59 188.65 ⚪ -5%
⏱️ Latency P50 85.42 ms 91.12 ms 🔴 +6.7%
⏱️ Latency P95 199.36 ms 216.2 ms 🔴 +8.4%
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 91.12 216.2 11,799 188.65 +16.84
Account 173.77 319.76 621 10.4 +19.81
TablesDB 88.22 170.66 6,417 104.87 +9.09
Storage 84.33 198.95 3,105 52.54 +14.83
Functions 128.9 247.32 1,656 28.69 +10.48

Top API waits (after)

API request Max wait (ms)
storage.buckets.create 497.68
functions.variables.update 425.75
functions.create 425.65
account.name.update 423.09
account.prefs.update 404.99

@ChiragAgg5k
ChiragAgg5k merged commit 117ed61 into main Nov 11, 2026
66 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix-membership-realtime-privacy branch November 11, 2026 12:03
ChiragAgg5k added a commit that referenced this pull request Nov 12, 2026
fix(realtime): apply membership privacy to membership events (appwrite:appwrite:alert#4390)

(cherry picked from commit 117ed61)
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