Repository navigation
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @, @chubes4. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@chubes4 some early feedback here.
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change that rejects nonexistent users before two-factor provider logic runs.
No open issues 🎉
What changed in this PR
This PR addresses #937 by rejecting nonexistent users in the shared REST permission check before recovery-code or TOTP provider logic runs. It extracts a focused prerequisite from #935’s broader REST API work.
Changes:
- Adds a capability-first user validation helper that returns
rest_user_invalid_id(404) for missing users. - Applies validation before the existing Two-Factor revalidation check.
- Adds regression tests for recovery-code generation with user ID
0, both with and without provider enablement.
| File | Description |
|---|---|
tests/providers/class-two-factor-backup-codes-rest-api.php |
Tests error responses, absence of generated codes and download links, and unchanged user metadata. |
class-two-factor-core.php |
Adds user-existence validation to the shared REST permission callback. |
Review effort: Balanced
What?
Split out of #935 as requested there. The REST permission callback shared by the recovery-code and TOTP routes now rejects a
user_idthat does not resolve to an existing user withrest_user_invalid_id(404), before any provider logic runs.Fixes #937
Why?
POST /two-factor/1.0/generate-backup-codeswith{"user_id":0}currently returns HTTP 200 with ten generated codes plus PHP warnings, and withenable_provider: trueit reaches a database failure and returns HTTP 500. Details and fuzz evidence are in #937.How?
Two_Factor_Core::rest_api_can_edit_user( $user_id ): checksedit_userfirst (so unauthorized callers cannot probe which IDs exist), thenfetch_user(), returning a 404WP_Errorfor missing users.rest_api_can_edit_user_and_update_two_factor_options()calls it before the revalidation check, so every route using that callback (recovery codes, TOTP create/delete) gets the same behavior.Testing
Two tests in
tests/providers/class-two-factor-backup-codes-rest-api.phpcover both reproductions from #937: a 404rest_user_invalid_id, no codes or download link in the response, and no user meta written for user 0. PHPUnit turns warnings into failures, so the tests also prove provider logic is never reached.Written directly by Extra Chill Bot (AI agent) for Chris Huber.