Repository navigation
fix(auth,databases): restrict account keys to console; gate increment/decrement; fix upsert perms; drop guest embeddings - #14755
Conversation
…/decrement, fix upsert perms, drop guest embeddings
- Account API keys are refused on any project other than console, in the HTTP auth
gate and the realtime connection resource. Previously an account key (empty
projectId) injected the console user's roles into any target project, where
caller-chosen console user/org IDs can collide with a project's user/team IDs.
Also tightens the project-scoped admin role match to require an exact
'project-{projectId}-' delimiter (defense-in-depth).
- Increment/decrement now honor the database and collection enabled flag for
non-privileged callers, like every other document action.
- Upsert role-checks only caller-supplied permissions, not permissions inherited
from the existing document (parity with update).
- Remove embeddings.write from the guests role; embedding generation is backed
compute with no per-resource gate.
Refs appwrite-labs/cloud#6747, appwrite-labs/cloud#6749, appwrite-labs/cloud#6752, appwrite-labs/cloud#6753, appwrite-labs/cloud#6754
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
🧹 Nitpicks (1) — 🟢 1 low
The change tightens auth boundaries and fixes two permission-model defects. Account API keys are now rejected on non-console projects in the REST auth path, with a matching (but looser) guard in realtime, and the
Reviewed commit: 70ebe83 |
🟢 Tier S · Ready to merge
The change confines account API key authentication to the console in HTTP and realtime, tightens project-specific admin role matching, and removes embedding generation from guest scopes. It also applies enabled checks to document increment/decrement and avoids rechecking inherited upsert permissions, with regression coverage for these behaviors.
📂 Walkthrough · 9
Reviewed |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
There was a problem hiding this comment.
This PR restricts account API keys to the console project, removes embeddings.write from the guests role, enforces the collection enabled gate on increment/decrement, and stops upsert from re-validating inherited permissions.
Key findings
- 🟡 Realtime silently downgrades account keys instead of rejecting — connection.php:289
| if (!empty($accountKeyUserId) && !empty($accountKey) && $project->getId() === 'console') { | ||
| if (!$user->isEmpty()) { | ||
| throw new Exception(Exception::USER_API_KEY_AND_SESSION_SET); |
There was a problem hiding this comment.
🟡 bug · medium
Realtime silently downgrades account keys instead of rejecting
The PR rejects account API keys on non-console projects in app/controllers/shared/api.php:260 by throwing USER_UNAUTHORIZED, but the parallel realtime guard wraps the whole account-key block in a $project->getId() === 'console' condition, so on any other project the block is skipped rather than rejected (app/init/realtime/connection.php:289). A realtime connection presenting an account key therefore proceeds as a guest (or with an unrelated session) with no error, and the USER_API_KEY_AND_SESSION_SET conflict check is also skipped, so a session+key combination is accepted there but rejected on every REST route. Realtime clients get silently unauthenticated subscriptions instead of the 401 the REST surface returns for the same credentials.
📋 Prompt for AI Agents
In app/init/realtime/connection.php around lines 284-307, restructure the account-key block so that when both x-appwrite-user and x-appwrite-key headers are non-empty and the project is not 'console', the code throws new Exception(Exception::USER_UNAUTHORIZED, 'Account API keys can only be used with the console project.') — matching the guard added in app/controllers/shared/api.php around line 260. Keep the existing console-project branch (the USER_API_KEY_AND_SESSION_SET conflict check, key lookup, and expiry check) unchanged for the console project.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
… ignoring them The realtime guard wrapped the whole account-key block in a console-project condition, so on any other project the credentials were silently skipped: a key-only client fell through to a guest connection and a key+session request avoided the mutual-authentication error. Reject them with USER_UNAUTHORIZED, matching the HTTP auth gate. Addresses review on #14755. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Addressed the two findings:
|
|
@hansi-codes review All prior findings are resolved. What would it take for this PR to reach Tier S rather than Tier A? |
Adds testProjectSpecificPermissionsPrefixCollision: two projects whose IDs are
prefix siblings (A is a prefix of B), a member granted project-{B}-owner, asserting
they see and can read B only, never A. Locks in the cross-project authorization
boundary the exact 'project-{projectId}-' delimiter match protects.
Addresses review on #14755.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Added One honest caveat on this boundary: the project list/read filter matches the member's team role ( @hansi-codes review |
…ement, fix upsert perms (backport #14755) - Account API keys are refused on any project other than console, over HTTP and realtime, and project-scoped admin roles match an exact project-{id}- boundary. - Increment and decrement honor the database and collection enabled flags. - Upsert role-checks only caller-supplied permissions, not inherited ones. - Guests cannot generate embeddings. 1.9 has no embeddings.write scope (the route uses documents.write, which guests hold), so the text embeddings action refuses callers with neither a user nor a key. (cherry picked from commit bb790c1)
…ement, fix upsert perms (backport #14755) - Account API keys are refused on any project other than console, over HTTP and realtime, and project-scoped admin roles match an exact project-{id}- boundary. - Increment and decrement honor the database and collection enabled flags. - Upsert role-checks only caller-supplied permissions, not inherited ones. - Guests cannot generate embeddings. 1.9 has no embeddings.write scope (the route uses documents.write, which guests hold), so the text embeddings action refuses callers with neither a user nor a key. (cherry picked from commit bb790c1)
…authz fix(auth,databases): restrict account keys to console; gate increment/decrement; fix upsert perms; drop guest embeddings (cherry picked from commit bb790c1)
What
Authorization and isolation fixes on the Databases document surface and the shared auth gate, each with a regression that fails before the change and passes after.
Account API keys restricted to the console project (Critical)
An account API key has an empty
projectId, so the project-binding check was skipped and theAPI_KEY_ACCOUNTbranch injected the console user's roles —user:{id},users,team:{orgId}for each confirmed org membership — into any target project's authorization. Console user and organization IDs are caller-chosen, so they can be made to collide with a target project's own user/team IDs. Fix: reject account keys on any project other thanconsole, in both the HTTP auth gate and the realtime connection resource. Also tightens the project-scoped admin role match to require an exactproject-{projectId}-delimiter (a prefix likeproject-app2-ownerpreviously matched projectapp); this one is defense-in-depth — the admin-mode project-read gate already blocks cross-project data access.Increment/decrement honor the
enabledflagThese two actions skipped the enabled gate that every other document action applies, so a client with update permission kept mutating numeric attributes in a disabled database/collection. Now 404 for non-privileged callers, like the sibling actions. Inherited by the DocumentsDB and TablesDB subclasses.
Upsert no longer re-validates inherited permissions
When no
permissionswere supplied, upsert inherited the existing document's permissions and then ran the grant role-check over them, wrongly refusing a user who could update a shared document whose stored permissions named another role. Now only caller-supplied permissions are checked (parity with update).Guests lose
embeddings.writeEmbedding generation is backed compute with no per-resource gate; an unauthenticated caller who knew a public project ID could drive the backend. Removed from the guests role.
Tests
AccountKeyCrossProjectTest(added in the Cloud repo, where account-key creation lives): console key works, customer-project use refused — covers the fix here.DatabasesBase::testDisabledCollectionBlocksIncrement(Legacy + DocumentsDB): increment on a disabled collection 200 → 404.DatabasesBase::testUpsertDoesNotRevalidateInheritedPermissions(Legacy + DocumentsDB): legitimate upsert of a shared document 401 → 200.Embeddings/GuestEmbeddingsTest: guestPOST /v1/embeddings/textis 401.🤖 Generated with Claude Code