add wp-config support to disable 2fa for a user#908
Open
masteradhoc wants to merge 1 commit into
Open
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 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Adds a
TWO_FACTOR_DISABLE_FOR_USERwp-config constant that disables the two-factor login challenge for one or more named users, so an operator with filesystem access can recover a locked-out account without database surgery or a second admin.Fixes # TBD
Why?
When a user loses their second factor and the site has no other administrator, today's only operator options are editing the database directly or un-checking options as a second admin. There is no supported
wp-config.phplever to bypass 2FA for a single account.This implements a per-user wp-config constant to improve the account recovery possibilities. Crucially, it is per-user, not site-wide, because disabling 2FA for everyone just because one person is locked out throws away the protection of every other account. Because the constant lives in
wp-config.php(filesystem access only), it carries the same trust level as shell/DB access and adds no new attack surface.Related discussion:
How?
Two small functions in
two-factor.php, registered intwo_factor_register_admin_hooks():two_factor_bypass_primary_provider_for_user()hooks the existingtwo_factor_primary_provider_for_userfilter. For a matching user it returnsnull, which makesTwo_Factor_Core::is_user_using_two_factor()reportfalsesowp_login()lets the user through without a second factor.get_userdata()and compared by ID, login, or email. The constant accepts a single identifier, a comma-separated list, or an array.two_factor_bypass_admin_notice()shows a standingadmin_noticeswarning (tomanage_optionsusers) whenever the constant is set, echoing the configured value so a forgotten bypass — or a typo — is easy to spot.Usage in
wp-config.php:Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8
Used for: Drafting the implementation and PR text. The hook choice, scope decision (per-user, no global switch), and final code were reviewed and edited by me.
Testing Instructions
admin) and confirm they normally get the second-factor prompt at login.define( 'TWO_FACTOR_DISABLE_FOR_USER', 'admin' );towp-config.php, then log out and log in asadminwith password only — confirm no 2FA prompt.admin— confirm the 2FA prompt returns and the notice is gone.'nobody') — confirm no user is bypassed and real 2FA users are still challenged.Screenshots or screencast
Changelog Entry