Skip to content

fix(users): require users.write to read MFA recovery codes - #14872

Merged
HarshMN2345 merged 1 commit into
mainfrom
fix-mfa-recovery-codes-scope
Oct 23, 2026
Merged

HarshMN2345 merged 1 commit into
mainfrom
fix-mfa-recovery-codes-scope

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

Changes the scope on GET /v1/users/:userId/mfa/recovery-codes from users.read to users.write, matching the create and update recovery-code endpoints. Extends UsersCustomServerTest to assert a users.read-only key gets 401 on that route.

Tested: e2e assertion added; vendor not installed in this worktree so lint/PHPStan will run in CI. Details are tracked internally.

@luxor-code-review

luxor-code-review Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Usage metric still tagged .read after scope bumped to users.write (Get.php:34) — The scope changed to users.write but the metric template still resolves to users.{scope}.requests.read (src/Appwrite/Platform/Modules/Users/Http/Users/MFA/RecoveryCodes/Get.php:34), producing the mixed bucket users.write.requests.read.

The change makes retrieving MFA recovery codes as privileged as regenerating them, matching RecoveryCodes/Create.php and RecoveryCodes/Update.php, with an e2e test asserting a users.read-only key is rejected.

Files Change
src/Appwrite/Platform/Modules/Users/Http/Users/MFA/RecoveryCodes/Get.php Scope label changed from users.read to users.write; the usage.metric label was left as requests.read.
tests/e2e/Services/Users/UsersCustomServerTest.php Adds an e2e case asserting a users.read-only API key now receives 401 on the recovery-codes GET endpoint.

One low-severity follow-up on the usage metric label is included; the authorization change itself is coherent with siblings and the scope lock contract (app/config/scopes/lock.json still contains both scopes, so ScopesTest.php is unaffected).

Reviewed commit: e8f9cd9

@ghost

ghost commented Oct 23, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The route scope aligns with the adjacent recovery-code endpoints, and the new E2E assertion covers the read-only key denial.

The MFA recovery-codes GET route now requires the users.write scope, matching its create and update counterparts. The custom-server E2E test now checks that an API key with only users.read is rejected for that route.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
src/Appwrite/Platform/Modules/Users/Http/Users/MFA/RecoveryCodes/Get.php Changed the route’s required scope from users.read to users.write.
tests/e2e/Services/Users/UsersCustomServerTest.php Added coverage that a users.read-only key cannot fetch MFA recovery codes.

Reviewed e8f9cd9 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost 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

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

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.

@HarshMN2345
HarshMN2345 merged commit a9f8ae1 into main Oct 23, 2026
35 checks passed
@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-mfa-recovery-codes-scope (after).

Metric Before After Change
🚀 Requests/sec 216.7 227.34 ⚪ +4.9%
⏱️ Latency P50 78.79 ms 77.49 ms ⚪ -1.6%
⏱️ Latency P95 184.75 ms 174.7 ms 🟢 -5.4%
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 77.49 174.7 13,965 227.34 -10.05
Account 145.39 245.81 735 12.23 -69.86
TablesDB 76.76 144.26 7,595 125.69 +1.31
Storage 67.68 156.13 3,675 62.97 -25.08
Functions 109.26 198.85 1,960 34.21 -36.37

Top API waits (after)

API request Max wait (ms)
functions.create 406.37
account.name.update 382.11
account.prefs.update 374.8
tablesdb.rows.create 347.81
tablesdb.rows.delete 296.12

ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…s-scope

fix(users): require users.write to read MFA recovery codes

(cherry picked from commit a9f8ae1)
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.

1 participant