Skip to content

fix(presences): keep the owner's update and delete when a client sets permissions - #14396

Merged
HarshMN2345 merged 5 commits into
mainfrom
fix-presence-owner-permissions
Oct 15, 2026
Merged

HarshMN2345 merged 5 commits into
mainfrom
fix-presence-owner-permissions

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

  • When a client session upserts or updates a presence with explicit permissions, PresenceState::setPermissions() now always adds update("user:<id>") and delete("user:<id>") for that user. Before, the given permissions replaced the owner's, so a presence shared with [Permission.read(Role.users())], as the docs show, could no longer be heartbeated, updated or deleted by its own owner.
  • API keys and privileged callers still get exactly the permissions they pass.
  • testUpsertPresenceWithReadPermissions covers the heartbeat, update and delete of a presence shared with read("users") only.

Verification

A client session on a local stack upserts its presence with permissions: ['read("users")'] (REST and realtime), then:

Step main this branch
PUT /v1/presences/:id again (heartbeat) 401 user_unauthorized 200
PATCH /v1/presences/:id {status: 'away'} 401 200
DELETE /v1/presences/:id 401 204
upsertPresence from a second realtime connection of the same user error 401 response

The created presence now carries delete("user:<id>"), read("users"), update("user:<id>"). testUpsertPresenceWithReadPermissions fails on main (401 on the heartbeat). The Presences e2e suite passes against this branch, except the two maintenance-expiry tests, which need the Docker socket my test container did not have. Pint and PHPStan pass on the changed file.

Fixes #14341

… permissions

A client that upserted its presence with only read roles, as the docs show,
could no longer heartbeat, update or delete it: the given permissions replaced
the owner's. Client-set permissions now always keep update and delete for the
user who wrote them.
@luxor-code-review

luxor-code-review Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Auto-grant gives delete to shared-role updaters (State.php:72) — The new auto-grant appends update and delete permissions for user:<self> to every non-API-key, non-privileged caller whose payload passes checkPermissions (src/Appwrite/Presences/State.php:72-76), not just the presence owner.

This PR modifies src/Appwrite/Presences/State.php so that callers updating a presence state who pass the permission check (and are not API keys or privileged users) are automatically granted update and delete permissions for their own user identity on the presence document.

Files Change
src/Appwrite/Presences/State.php Auto-appends update:user:<id> / delete:user:<id> permissions for the calling user during presence updates, alongside the existing permission validation flow.

Reviewed commit: 15106c8

@ghost

ghost commented Oct 12, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The newest permission-construction change is equivalent to the existing behavior and uses the same factory pattern found elsewhere in the repository.

Client-session presence permissions now retain the owner's update and delete access when custom sharing permissions are supplied, while API keys and privileged callers retain the permissions they provide. The presence e2e regression verifies that a client can heartbeat, update, and delete a presence shared with read-only permissions.

Latest changes: The newest commit switches owner update/delete permission construction to the Permission factory methods without changing the behavior.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
src/Appwrite/Presences/State.php Adds the owner's update and delete permissions for client sessions with custom sharing permissions.
tests/e2e/Services/Presences/PresenceBase.php Adds an e2e regression covering heartbeat, status update, and deletion of a read-shared presence.

Merged main (fe77843); no changes to this PR's code since c80218c · 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 A · Looks good to merge. Summary

Comment thread src/Appwrite/Presences/State.php Resolved
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • 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 Oct 12, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-presence-owner-permissions (after).

Metric Before After Change
🚀 Requests/sec 188.12 202.35 🟢 +7.6%
⏱️ Latency P50 90.82 ms 85.76 ms 🟢 -5.6%
⏱️ Latency P95 214.82 ms 198.55 ms 🟢 -7.6%
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 85.76 198.55 12,540 202.35 -16.27
Account 159.84 294.44 660 11.38 -27.74
TablesDB 81.94 152.41 6,820 113.67 -25.03
Storage 82.29 188.87 3,300 56.2 -3.18
Functions 119.69 226.9 1,760 30.6 -23.2

Top API waits (after)

API request Max wait (ms)
functions.create 507.07
account.name.update 475.26
functions.variables.update 430.06
functions.variables.delete 396.11
account.prefs.update 392.26

@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

@HarshMN2345
HarshMN2345 merged commit 5c37f84 into main Oct 15, 2026
12 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
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.

🐛 Bug Report: Presence created with the documented permissions can no longer be updated, heartbeated or deleted by its owner (401)

1 participant