SSO: Bypass local Two-Factor prompt when WP.com 2FA was completed#47306
SSO: Bypass local Two-Factor prompt when WP.com 2FA was completed#47306
Conversation
Two-Factor plugin 0.15.0+ unconditionally hooks wp_login at PHP_INT_MAX, which destroys the auth session and shows a local 2FA prompt — even for SSO logins that already completed 2FA on WordPress.com. When WP.com confirms two_step_enabled, remove Two-Factor's wp_login hook so SSO can complete without a redundant prompt. When WP.com 2FA is NOT active, the hook stays so Two-Factor can enforce local 2FA normally. See CONNECT-178
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
There was a problem hiding this comment.
Pull request overview
This PR fixes a conflict between Jetpack SSO and the Two-Factor plugin version 0.15.0+, where users were being double-prompted for 2FA even after completing it on WordPress.com. The Two-Factor plugin now unconditionally hooks wp_login at PHP_INT_MAX priority, which destroys the auth session that SSO just created.
Changes:
- Added conditional logic to remove Two-Factor's
wp_loginhook when the user has completed WP.com 2FA - Maintained the safety net behavior where local Two-Factor enforcement continues if WP.com 2FA is not active
- Updated changelog to document the fix
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| projects/packages/connection/src/sso/class-sso.php | Added logic to bypass Two-Factor plugin's wp_login hook when WP.com 2FA was completed, preventing redundant local 2FA prompts |
| projects/packages/connection/changelog/fix-sso-two-factor-bypass | Added changelog entry documenting the fix for the Two-Factor 0.15.0+ conflict |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code Coverage SummaryCoverage changed in 1 file.
|
|
Thanks for working on this @kraftbj !
Something like this, building on your existing block: What do you think — worth the addition? |
See CONNECT-178
Proposed changes:
Two-Factor plugin 0.15.0+ changed how it hooks into WordPress authentication—both the
authenticatefilter andwp_loginaction are now registered unconditionally inadd_hooks(). Since SSO'shandle_login()firesdo_action('wp_login', ...)directly, Two-Factor's handler destroys the session, clears the auth cookie SSO just set, and shows a local 2FA prompt. The user ends up double-prompted for 2FA even though they already completed it on WordPress.com.This PR takes the approach of accepting WP.com 2FA as a valid second factor rather than fully restoring the old behavior. When WP.com confirms
two_step_enabled, we remove Two-Factor'swp_loginhook before it can intercept—SSO completes normally. When WP.com 2FA is NOT active, the hook stays in place and Two-Factor enforces local 2FA as usual. The idea is that if someone has Two-Factor installed, they want 2FA on login, and WP.com 2FA satisfies that intent.This is safe across Two-Factor versions:
wp_loginhook wasn't registered during SSO (it was conditional insidefilter_authenticate).remove_actionis a no-op.remove_actionremoves it, preventing the redundant prompt.class_exists('Two_Factor_Core')is false, block is skipped entirely.Other information:
Jetpack product discussion
What do you think about this approach, @bindlegirl? The alternative would be to fully restore the old behavior (always bypass Two-Factor during SSO regardless of WP.com 2FA status). This version felt more aligned with the intent of having Two-Factor installed—you want 2FA on login, and WP.com 2FA counts. But if you'd rather just fully restore the previous behavior, that's a one-line change (drop the
two_step_enabledcheck).See WordPress/two-factor#811
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
Changelog