Repository navigation
fix(realtime): apply membership privacy to membership events (appwrite:appwrite:alert#4390) - #15176
Conversation
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]>
|
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.
Reviewed commit: 1202ab9 |
🟢 Tier S · Ready to mergeMembership 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 Latest changes: The new commit quotes
📂 Walkthrough · 3
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
Co-Authored-By: Claude Opus 5 <[email protected]>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
fix(realtime): apply membership privacy to membership events (appwrite:appwrite:alert#4390) (cherry picked from commit 117ed61)
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 roleteam:{teamId}, which every confirmed member holds, and the payload it carries is the HTTP response rendered for the writing caller:Memberships/Create.phpandMemberships/Update.phprenderuserName/userEmailbehind$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.membershipsUserIdpolicy at all, souserIdis always present.app/controllers/shared/api.phpcopies that response into the event,Realtime::from()forwards it, andRealtime::getRealtimePayload()stripped only keys explicitly markedsensitive— of which these routes set none.Realtime/Event/Handler.phpserializes 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 tofalse, i.e. hidden, for newly created projects), an ordinary member holding an openmemberships/teams.<id>subscription received exactly the fieldsGET /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 (truefor name/email/phone/id/MFA so existing projects keep today's behaviour,falseforuserAccessedAt).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:
payloaddirectly, notgetRealtimePayload(), and are configured by the project owner.RealtimeAdapter::fromPayload()still receives the full payload, so thedeleteevent's extrauser:{userId}addressing (which lets the removed member receive it) keeps working.app/config/console.phpsets every membership privacy flag totrue, so console membership events are untouched.Test Plan
TDD:
tests/unit/Event/RealtimeTest.phpgainedtestMembershipPayloadDropsFieldsHiddenByPrivacyPolicy, which failed on the pre-fix code withFailed asserting that an array does not have the key 'userName'and passes after, plustestMembershipPayloadKeepsFieldsAllowedByPrivacyPolicypinning that a project which allows the fields keeps broadcasting them.End-to-end,
RealtimeCustomClientTest::testChannelMembershipsPrivacyhas an ordinary confirmed member listening onmembershipswhile 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.Unit suite: 2458 tests, the only errors are the pre-existing
Auth\KeyTest(no JWT signing key) andDatabases\ListCacheTest(no Redis) environment failures.composer lintandphpstanclean on the changed files.Related PRs and Issues
Have you read the Contributing Guidelines on issues?
Yes.
🤖 Generated with Claude Code