Skip to content

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

Closed

Description

@JoshiJoshiJoshi

👟 Reproduction steps

  1. Self-hosted Appwrite 2.4.0, a signed-in user (client session).
  2. Create a presence exactly as in the docs (/docs/apis/realtime/presences):
    await presences.upsert({ presenceId, status: 'online', permissions: [Permission.read(Role.users())] });
    → 200, the record has $permissions: ["read(\"users\")"] only.
  3. Follow the documented heartbeat pattern and upsert again with the same arguments → 401 user_unauthorized.
  4. presences.update({ presenceId, status: 'away' }) → 401.
  5. presences.delete({ presenceId }) (documented for sign out) → 401.
  6. Same over Realtime: realtime.upsertPresence({ status: 'online', permissions: [Permission.read(Role.users())] }) works once; the next upsertPresence on the same or another connection of the same user returns an error with code 401.

Without permissions, or with update("user:<id>")/delete("user:<id>") added, every step succeeds.

👍 Expected behavior

As documented: "Client sessions can always update their own presence without an extra scope." The owner can heartbeat, change status and delete their presence regardless of which read roles were granted.

👎 Actual Behavior

Passing permissions replaces the default owner permissions entirely, so a presence created with only read roles is read-only for its own owner. Heartbeat, status change and sign-out cleanup all fail with 401. Over REST the stale presence then lingers until expiresAt; over Realtime until the connection closes. Reproduced 2 of 2 runs, REST and Realtime.

Cause: Presences\State::setPermissions() uses the given permissions as-is and only adds owner permissions when permissions is null; upsertForUser() then updates the existing row through upsertDocument()/updateDocument(), which requires update permission. The same code is in every release since 2.0.0.

📄 Related docs problem

The "Scoping who can see a presence" section shows a client-web example that shares a typing indicator only with the DM recipient: permissions: [Permission.read(Role.user('<RECIPIENT_USER_ID>'))]. From a client session this always fails with 401 Permissions must be one of: (…) (REST and Realtime, reproduced 2/2), because a client may only grant roles it holds itself (Presences\State::checkPermissions()). The same applies to Role.team() for teams the user is not in and to labels. The example only works from a server SDK, which the docs do not say.

🎲 Appwrite version

2.4.0; the same code exists since presences were introduced in 2.0.0

💻 Operating system

Linux (Debian 12), Docker

🧱 Your Environment

Self-hosted, Postgres adapter, two API/realtime nodes.

💡 Suggested fix

Either always grant the owning user update/delete on their own presence (as the docs promise), or authorize presence writes by userId ownership instead of document permissions. Alternatively fix the docs and every SDK example to include Permission.update(Role.user(userId)) and Permission.delete(Role.user(userId)).

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find a similar issue

🏢 Have you read the Code of Conduct?

  • I have read the Code of Conduct

Activity

  1. added
    api / realtime
    product / auth
    product / databases
    product / sites
    sdk / cli
    on Oct 11, 2026
  2. nk0273926 commented on Oct 12, 2026

    @nk0273926

    I'd like to work on this issue. The root cause appears to be that explicitly passing permissions replaces the default owner permissions, leaving the presence owner unable to update or delete their own presence.

    I propose ensuring that the owning user retains the necessary update and delete permissions, even when custom read permissions are supplied, in accordance with the documented behavior. I'll also investigate the client-side permission validation issue and update or add regression tests covering REST and Realtime presence upserts, updates, and deletion with custom permissions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api / realtimeproduct / authproduct / databasesproduct / sitessdk / cli

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions