Repository navigation
#953 - Email account owner when two-factor settings change - #1001
masteradhoc wants to merge 7 commits into
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. |
There was a problem hiding this comment.
🟡 Changes recommended
Some provider-change paths miss notifications, and the email inaccurately claims that all sessions were logged out.
4 open issues
What changed in this PR
Adds account-owner email notifications for two-factor provider changes, addressing the silent security changes described in #953.
Changes:
- Adds provider-change emails with filterable content and site-branded subjects.
- Connects notifications to profile saves and the shared CLI session-reset helper.
- Adds notification tests and mail-fixture cleanup.
| File | Description |
|---|---|
| tests/class-two-factor-core.php | Tests notification delivery, recipients, and content filtering. |
| CLI/class-two-factor-cli-command.php | Adds notifications to the provider-change helper. |
| class-two-factor-core.php | Builds notification emails and sends them after profile changes. |
Review effort: Balanced
| WP_Session_Tokens::get_instance( $user->ID )->destroy_all(); | ||
| } | ||
|
|
||
| Two_Factor_Core::notify_user_two_factor_settings_changed( $user, $providers_after, $providers_before ); |
| return false; | ||
| } | ||
|
|
||
| $supported_providers = self::get_supported_providers_for_user( $user->ID ); |
| // (see the conditions in user_two_factor_options_update()), the account owner is told | ||
| // their sessions were logged out: it's true often enough, and simpler than trying to | ||
| // explain the exact conditions under which the plugin invalidates other sessions. | ||
| $changes[] = __( 'All open sessions have been logged out.', 'two-factor' ); |
| } | ||
| } | ||
|
|
||
| self::notify_user_two_factor_settings_changed( $user, array_keys( $enabled_providers ), $existing_providers ); |

What?
Emails the account owner whenever their two-factor authentication methods change — a provider is activated or deactivated via the profile page or via WP-CLI (
wp two-factor enable/disable).Fixes #953
Related #476
Why?
Enrolling or removing a factor destroys the account's other active sessions (
wp_destroy_other_sessions()/WP_Session_Tokens::destroy_all()) with no notification — indistinguishable from an unauthorized logout, especially when an administrator makes the change on a user's behalf. #953 asked for an email notification here, following the same pattern already used by this plugin's compromised-password-reset emails. core trac #63927 — which adds an equivalent notification when a new application password is created — was cited as supporting precedent for adding this kind of security-event email.How?
Two_Factor_Core::notify_user_two_factor_settings_changed( $user, $enabled_providers, $existing_providers ), which diffs the before/after provider lists and emails the account owner listing which methods were activated/deactivated, plus a line noting that all open sessions were logged out.two_factor_settings_changed_email(subject/message/headers/recipient).user_two_factor_options_update()(the profile-page save path)enable/disablecommands, via the shareddestroy_sessions_if_providers_changed()helper, so a change made out-of-band via the CLI is reported the same way a UI change would be.[Site Name] Your two-factor authentication settings have changed), matching the bracketed-subject convention WP core uses for its own account-security emails.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5
Used for: Full implementation (new method, call-site wiring, PHPUnit tests) drafted by the assistant per my direction across several review rounds (wording, removing the session-destroyed conditional, subject line,
@sinceversioning). I reviewed and directed every change before it was committed.Testing Instructions
npm run env start && npm run buildhttp://localhost:8025).wp two-factor enable <user> Two_Factor_Emailandwp two-factor disable <user> Two_Factor_Email— confirm each sends the same notification.npm test— new coverage lives intests/class-two-factor-core.php(search fornotify_user_two_factor_settings_changed/settings_changed_notification).Screenshots or screencast
N/A — no UI changes.
Changelog Entry