Repository navigation
fix: prevent user enumeration on password recovery endpoint - #13438
Conversation
Greptile SummaryThe PR makes password-recovery responses uniform for active, blocked, and nonexistent accounts by creating and immediately deleting mock tokens for nondeliverable requests.
Confidence Score: 4/5The PR appears safe to merge, with a non-blocking concern that branch-specific request work may preserve a timing-based enumeration signal. The explicit status and payload leaks are removed and the mock token satisfies the persisted schema, but active requests still perform cache purge and mail enqueue operations that nondeliverable requests skip. Files Needing Attention: app/controllers/api/account.php
|
| Filename | Overview |
|---|---|
| app/controllers/api/account.php | Introduces a uniform recovery response and mock-token path, but leaves branch-specific synchronous work that may remain timing-distinguishable. |
| tests/e2e/Services/Account/AccountCustomClientTest.php | Adds response-shape coverage for nonexistent and blocked recovery requests, without testing timing equivalence. |
Prompt To Fix All With AI
### Issue 1
app/controllers/api/account.php:4028
**Branch-specific recovery timing**
If the branch-specific database and queue costs are distinguishable in deployment, active requests purge the user cache and enqueue mail while nondeliverable requests delete the temporary token and skip mail enqueueing, exposing account status through response timing. Align the synchronous work performed by both paths to avoid retaining this enumeration signal.
**How this was verified:** The two deliverability branches invoke different database, cache, and mail-publisher operations before the response is returned.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "fix: prevent user enumeration on passwor..." | Re-trigger Greptile
| customMailOptions: $project->getId() === 'console' ? ['senderName' => $platform['emailSenderName']] : [], | ||
| platform: $platform, | ||
| )); | ||
| if ($deliverable) { |
There was a problem hiding this comment.
Branch-specific recovery timing
If the branch-specific database and queue costs are distinguishable in deployment, active requests purge the user cache and enqueue mail while nondeliverable requests delete the temporary token and skip mail enqueueing, exposing account status through response timing. Align the synchronous work performed by both paths to avoid retaining this enumeration signal.
How this was verified: The two deliverability branches invoke different database, cache, and mail-publisher operations before the response is returned.
Knowledge Base Used: Account authentication and identity
Prompt To Fix With AI
This is a comment left during a code review.
Path: app/controllers/api/account.php
Line: 4028
Comment:
**Branch-specific recovery timing**
If the branch-specific database and queue costs are distinguishable in deployment, active requests purge the user cache and enqueue mail while nondeliverable requests delete the temporary token and skip mail enqueueing, exposing account status through response timing. Align the synchronous work performed by both paths to avoid retaining this enumeration signal.
**How this was verified:** The two deliverability branches invoke different database, cache, and mail-publisher operations before the response is returned.
**Knowledge Base Used:** [Account authentication and identity](https://app.greptile.com/appwrite/-/custom-context/knowledge-base/appwrite/appwrite/-/docs/account-authentication.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
The timing concern is acknowledged but considered impractical to exploit given the existing rate limiting (10/hour), network jitter, and the fact that both branches perform comparable DB operations (create+purge vs create+delete). The primary enumeration vector (response body/status code) is fully closed by this PR.
There was a problem hiding this comment.
That’s fair. The PR closes the primary enumeration vector by normalizing the status and response shape, and the existing rate limiting plus comparable token DB work substantially reduces the practical timing risk. I’ll treat the branch-specific timing difference as defense-in-depth rather than a blocking issue; the remaining difference is that deliverable requests purge the user cache and enqueue mail while nondeliverable requests delete the temporary token.
Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.
|
Hey @abnegate and Appwrite team, this is my first time creating a PR on Appwrite. Let me know if anything seems wrong and I’ll fix it. The Greptile comment is non-blocking. |
What does this PR do?
This PR fixes a user enumeration vulnerability in the
POST /v1/account/recoveryendpoint.Previously, the endpoint threw a
404(Exception::USER_NOT_FOUND) for unregistered emails and a401(Exception::USER_BLOCKED) for blocked users. This allowed malicious actors to enumerate registered and active users via an unauthenticated endpoint.This fix standardizes the behavior so that the endpoint always returns a
201 Createdwith an identical response payload structure regardless of whether the account exists, is blocked, or is active.Key Changes:
USER_NOT_FOUNDandUSER_BLOCKED.ID::unique()) for$id,userId, anduserInternalIdto ensure the response payload perfectly mirrors a successful request.Test Plan
Added comprehensive E2E tests in
tests/e2e/Services/Account/AccountCustomClientTest.phpto explicitly verify that the enumeration vulnerabilities are closed:[email protected]) returns a201 Createdand a valid mock payload structure with nosecretorphrase.201 Createdwith a valid mock payload.To verify locally:
Related PRs and Issues
account.createRecovery/ POST to/account/recoveryallows user enumeration #13435Checklist