Skip to content

fix(account): answer an unknown user like a wrong secret on token confirmation - #15990

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/token-confirm-unknown-user
Nov 26, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/token-confirm-unknown-user

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

The public token-confirmation routes answered differently for an unknown user and for a wrong secret: 404 user_not_found against 401 user_invalid_token. A caller holding no secret could use that difference to learn which user IDs exist, and so which addresses have accounts, given the ID a token-creation call returns.

An unknown user now gets 401 user_invalid_token, the same answer as a wrong secret, on:

  • PUT /v1/account/recovery
  • PUT /v1/account/recovery/otp
  • PUT /v1/account/verifications/email
  • PUT /v1/account/verifications/email/otp
  • PUT /v1/account/verifications/phone

The session-confirmation routes already answered this way. A valid secret still works exactly as before.

This closes the confirmation half of https://github.com/appwrite/appwrite/security/code-scanning/4958. The other half isn't covered here: magic-URL and email/phone OTP token creation return the real user ID when the address already has an account, and clients need that ID to create the session. That change to the login API is tracked separately.

Test Plan

The four e2e cases that used an unknown user ID on these routes (verification, recovery, email OTP verification, recovery OTP in AccountCustomClientTest) now expect 401 with type user_invalid_token.

Pint, Rector and PHPStan pass on the changed files.

Verification

  • The four changed e2e cases in AccountCustomClientTest (verification, recovery, email OTP verification, recovery OTP) passed in CI run 45356568256, in Tests / E2E / PostgreSQL (dedicated) / Account.
  • Not reproduced on staging. The confirmation routes are public, project-scoped account routes, and the CLI's account commands did not reach the temporary project's users: a user I had just created there was reported as not found.

🤖 Generated with Claude Code

Related: appwrite-labs/cloud#6666

@appwrite

appwrite Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Code review

Commit Status Tier Verdict Details
a95bc17 Reviewed Reviewed 🟢 S · Ready to merge ✅ Approved View review

This updates account recovery and verification confirmation handlers to return user_invalid_token for unknown user IDs, matching wrong-secret responses. It also updates E2E expectations for four of the affected routes.

Latest changes: The latest commit updates the phone-verification E2E case to expect status 401 and the user_invalid_token error type for an unknown user.

Walkthrough (6)
File Change
src/Appwrite/Platform/Modules/Account/Http/Account/Recovery/OTP/Update.php Maps unknown users to the invalid-token response on OTP recovery.
src/Appwrite/Platform/Modules/Account/Http/Account/Recovery/Update.php Maps unknown users to the invalid-token response on link-based recovery.
src/Appwrite/Platform/Modules/Account/Http/Account/Verifications/Email/OTP/Update.php Maps unknown users to the invalid-token response on email OTP verification.
src/Appwrite/Platform/Modules/Account/Http/Account/Verifications/Email/Update.php Maps unknown users to the invalid-token response on email verification.
src/Appwrite/Platform/Modules/Account/Http/Account/Verifications/Phone/Update.php Maps unknown users to the invalid-token response on phone verification.
tests/e2e/Services/Account/AccountCustomClientTest.php Updates unknown-user response assertions for recovery and email verification routes.

Reviewed the commits since a95bc17

Tip

Comment @appwrite review to re-run, or mention @appwrite with a question.

@appwrite appwrite Bot 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

@appwrite appwrite Bot 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

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Security rules

WARNING (1 new) — review signal only; does not fail the job.

php.appwrite.weak-secret-env-default (1)

Secret-like env var (SECRET, KEY, PASS, PASSWORD, TOKEN) read with a non-empty literal default. If the variable is unset the process silently runs with a shared, guessable value. Default to '' and fail or disable the feature when it is empty.

  • app/init/resources.php:354 — resource logs
    • What's wrong: _APP_USAGE_PASS falls back to 'appwrite' when unset, so every install that does not set it shares that value.
    • How to fix: Read System::getEnv('_APP_USAGE_PASS', '') and fail or disable the dependent connection when it is empty; keep the example value in .env / app/config/variables.php.
6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • 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

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/token-confirm-unknown-user (after).

Metric Before After Change
🚀 Requests/sec 195.55 214.46 🟢 +9.7%
⏱️ Latency P50 88.21 ms 79.93 ms 🟢 -9.4%
⏱️ Latency P95 212.22 ms 194.15 ms 🟢 -8.5%
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 79.93 194.15 13,623 214.46 -18.07
Account 152.96 325 717 11.97 -35.68
TablesDB 76.92 144.57 7,409 120.03 -15.18
Storage 73.51 167.54 3,585 59.38 -18.62
Functions 116.63 235.74 1,912 32.41 -14.11

Top API waits (after)

API request Max wait (ms)
storage.files.preview 556.01
account.get 514.64
functions.variables.update 438.92
functions.variables.delete 420.21
account.name.update 405.56

@ChiragAgg5k ChiragAgg5k self-assigned this Nov 24, 2026
@ChiragAgg5k
ChiragAgg5k merged commit fc6d659 into main Nov 26, 2026
43 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/token-confirm-unknown-user branch November 26, 2026 11:35
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.

2 participants