Repository navigation
fix: harden account claims, user credential responses and console realtime - #14976
Conversation
Claiming an unverified account through a magic URL or email OTP session, password recovery, or accepting an invite while signed out now revokes the credentials the registrant left behind, as OAuth and ID token claims already did. Revocation also drops console account keys.
A session or delegated token that can read users but not write them no longer receives password hashes, hash options or provider tokens. Standard API keys keep them, since user migrations read hashes.
…read roles Console copies of execution updates now go to those who can read the project instead of the execution's project-user roles, deployment events follow the project's read roles instead of the whole organization, and execution logs and errors stay out of realtime payloads as they do over HTTP for non-key callers.
|
Review complete. 🟠 2 high · 🟡 1 medium 💬 Inline comments (2)
📍 Findings outside the diff (1) — 🟠 1 high — defects on lines GitHub can't attach comments to🟠 High — Email-verification confirm endpoints skip credential revocation · account.php:5464 · // app/controllers/api/account.php
5464 $profile = $dbForProject->updateDocument('users', $profile->getId(), new Document(['emailVerification' => true]));The PR adds The change adds
Reviewed commit: ef8b4c4 |
🟢 Tier S · Ready to mergeThis PR revokes credentials left on unverified accounts across email-claim and recovery flows, including console account keys and edition-specific credentials. It also limits sensitive user credential fields for read-only callers and adjusts realtime event permissions and payloads for console consumers, project readers, and execution logs. E2E and unit tests cover the affected claim, authorization, and realtime behavior. Latest changes: The latest commits update the remaining console-tail membership setup to pass the member object expected by its helper and change the sites test to sign in before invite acceptance, since signed-out acceptance now revokes credentials.
📂 Walkthrough · 17
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
There was a problem hiding this comment.
This PR closes an account-takeover window by revoking attacker-held credentials whenever an unverified email is claimed, and fixes console realtime role scoping for individually granted users.
Key findings
- 🟠 Email-verification confirm endpoints skip credential revocation — account.php:5464
- 🟠 Non-standard key types bypass credential-hiding gate — api.php:383
- 🟡 Recovery revokes on stale unlocked
emailVerificationread — account.php:4654
| $isStandardKey = ! empty($apiKey) && $apiKey->getType() !== API_KEY_OAUTH2; | ||
| if (\in_array('users.read', $scopes, true) && ! \in_array('users.write', $scopes, true) && ! $isStandardKey) { | ||
| $response->setHideCredentials(true); | ||
| } |
There was a problem hiding this comment.
🟠 security · high
Non-standard key types bypass credential-hiding gate
The exemption is $apiKey->getType() !== API_KEY_OAUTH2, but the comment scopes it to standard keys (app/controllers/shared/api.php:383). API_KEY_EPHEMERAL, API_KEY_ORGANIZATION, API_KEY_ACCOUNT, and legacy keys are all exempted too, so a users.read-only key of those types still receives unhidden credential fields (passwordHash, hashOptions, MFA secrets) where sessions, OAuth2 keys, and JWTs are now blanked. This weakens the new gate to nearly a no-op for programmatic keys.
📋 Prompt for AI Agents
In app/controllers/shared/api.php at lines 382-386, replace $isStandardKey = ! empty($apiKey) && $apiKey->getType() !== API_KEY_OAUTH2; with an allowlist of key types that legitimately read user hashes (e.g. in_array($apiKey->getType(), [API_KEY_STANDARD], true)), so ephemeral and other non-standard key types with users.read-only scopes no longer bypass $response->setHideCredentials(true). Update the comment on line 382 to match the actual exemption list.
There was a problem hiding this comment.
Intentional. Every non-OAuth2 key is minted by someone who already holds keys authority and could grant users.write on it, so blanking would not take the credentials away from them, and Appwrite-to-Appwrite user migrations read hashes with a users.read key. OAuth2 tokens are the exception because they delegate a person's role, which may be read-only. I reworded the comment to say this.
There was a problem hiding this comment.
The updated comment and variable rename ($isMintedKey) improve clarity, but the underlying logic is unchanged — the exemption is still $apiKey->getType() !== API_KEY_OAUTH2, which means API_KEY_EPHEMERAL, API_KEY_ORGANIZATION, API_KEY_ACCOUNT, and legacy key types all remain exempt.
The 'minter holds keys authority' rationale applies to standard app keys, but ephemeral keys (short-lived, scoped) and organization/account keys may be issued to contexts where users.write was never in scope and the minter never intended to grant credential access. The fix the finding requested is an allowlist — e.g. in_array($apiKey->getType(), [API_KEY_STANDARD], true) — so only key types with a legitimate migration use-case bypass the gate, rather than exempting everything that isn't OAuth2. The current diff does not implement that change.
There was a problem hiding this comment.
Each of those types traces back to someone who already holds users.write, so an allowlist would not narrow anything:
- Ephemeral keys are minted by the platform for function and site executions, with scopes from the resource's config. Only
functions.write/sites.writecan set those, which in the role config means developer or above, and those roles carryusers.write. - Organization keys need
organization.keys.write(owner or developer). - Account keys are refused on every project except console (
Account API keys can only be used with the console project), so they never reach a project's users or credentials.
Analyst and editor hold none of these minting scopes, which is why OAuth2 tokens (which delegate the holder's own role) are the only key path left that needs the gate.
There was a problem hiding this comment.
The rationale is detailed and worth considering, but it hinges on invariants enforced elsewhere in the codebase — specifically that every non-OAuth2 key type is always minted by a principal who already holds 'users.write'. That is a runtime guarantee, not something the gate itself enforces. If any of those paths (ephemeral scope config, org key issuance, account key project check) ever changes or has an edge case, the gate silently fails open for credential fields.
The allowlist approach ('in_array($apiKey->getType(), [API_KEY_STANDARD], true)') would make the gate's safety self-contained and not reliant on those external invariants holding forever. The current diff still uses the denylist ('!== API_KEY_OAUTH2'), so the finding remains unaddressed in the code as shown.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Also documents why minted keys keep credential fields.
…ution logs over HTTP
|
On the out-of-diff finding about |
Reworked to a delivery-only fix (aligns with #14976): an event's own read roles — e.g. an execution's user:{id} — are meaningful only in its project's subscription tree. The same role delivered to the shared console tree matches an unrelated console account with that id. trigger() now re-addresses the console copy to the project's read roles (getPermissionsByType(Read)) so only real org members receive it; the project copy is unchanged, so the end user still does. Reverts the earlier stored-permission/threading approach (Create.php, worker, Func/Event, api init hook, publishers), which mutated the execution's stored permission and caused read regressions — the delivery layer is the right place, and stored permissions are left untouched. Co-Authored-By: Claude Opus 4.8 <[email protected]>
What does this PR do?
Hardening for account claims, user credential responses and console realtime fan-out.
Account claims
User::revokeCredentialsalso removes the account's console account keys, and triggers acredentialsRevokedhook so an edition can revoke credentials it keeps in its own collections.User credentials
users.readwithoutusers.write(a read-only console role, or a delegated OAuth2 token) get password hashes, hash options and provider tokens blanked, using the existingcredentialmodel flag. Standard API keys are unchanged because user migrations read hashes withusers.read.Realtime
logsanderrorsare kept out of realtime payloads, as they already are over HTTP for non-key callers. Webhooks still carry them.Test Plan
MessagingTest::testFromPayloadDeploymentsReachOnlyProjectReaders(functions and sites).testCreateMagicURLSessionRevokesUnverifiedAccountCredentials,testUpdateRecoveryRevokesUnverifiedAccountCredentials,testUpdateMembershipStatusRevokesUnverifiedAccountCredentials.Related PRs and Issues
None.
Checklist