add wp-config support to disable 2fa for a user#908
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. |
Verifies the functionality of the 2FA bypass mechanism, including user matching by ID, login, and email, support for comma-separated strings, and the display of the administrative warning notice.
This prevents potential errors if the `two_factor_primary_provider_for_user` filter returns an empty value.
add tests for the TWO_FACTOR_DISABLE_FOR_USER constant
|
Small Playground preview fix: the current preview URL points at
So the minimal fix is just changing the "url": "https://github.com/masteradhoc/two-factor.git",
"ref": "621-support-wpconfig-entry"If we want the Playground link to demo this feature rather than only install the PR branch, this blueprint also defines the wp-config constant, seeds the {"$schema":"https://playground.wordpress.net/blueprint-schema.json","preferredVersions":{"php":"8.2","wp":"latest"},"landingPage":"/wp-admin/","steps":[{"step":"defineWpConfigConsts","consts":{"TWO_FACTOR_DISABLE_FOR_USER":"admin"}},{"step":"installPlugin","pluginData":{"resource":"git:directory","url":"https://github.com/masteradhoc/two-factor.git","ref":"621-support-wpconfig-entry","path":"/"},"options":{"activate":true}},{"step":"runPHP","code":"<?php require_once '/wordpress/wp-load.php'; $user = get_user_by( 'login', 'admin' ); if ( $user && class_exists( 'Two_Factor_Core' ) ) { update_user_meta( $user->ID, Two_Factor_Core::ENABLED_PROVIDERS_USER_META_KEY, array( 'Two_Factor_Email' ) ); update_user_meta( $user->ID, Two_Factor_Core::PROVIDER_USER_META_KEY, 'Two_Factor_Email' ); }"},{"step":"login","username":"admin","password":"password"}]}Openable version: Playground demo for the wp-config per-user 2FA bypass |
|
@masteradhoc instead of writing exceptions into
For c3d759c, if the intention is not to provide a sitewide killswitch, this intention is defeated by allowing unlimited users to be defined as exceptions. It also opens some new error and abuse potential:
So, if
|
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