Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync two-factor session meta to newly created sessions #574

Merged
merged 3 commits into from
Jun 1, 2023

Conversation

dd32
Copy link
Member

@dd32 dd32 commented May 30, 2023

What?

Copies two-factor session information from the current session to newly created sessions.

Fixes #573

Why?

WordPress creates a new session when the user changes their password, for no particular reason.

See https://core.trac.wordpress.org/ticket/58427
See WordPress/wporg-two-factor#191

How?

Testing Instructions

See screen recording. The debug shown is from this change:

diff --git a/class-two-factor-core.php b/class-two-factor-core.php
index 53fa43b..ce5b197 100644
--- a/class-two-factor-core.php
+++ b/class-two-factor-core.php
@@ -1718,6 +1718,11 @@ class Two_Factor_Core {
                        $show_2fa_options ? '' : 'disabled="disabled"',
                );

+       echo '<pre>'; var_dump( [
+               'token' => wp_get_session_token(),
+               'session' => Two_Factor_Core::get_current_user_session(),
+       ] ); echo '</pre>';
+
                wp_nonce_field( 'user_two_factor_options', '_nonce_user_two_factor_options', false );
                ?>
                <input type="hidden" name="<?php echo esc_attr( self::ENABLED_PROVIDERS_USER_META_KEY ); ?>[]" value="<?php /* Dummy input so $_POST value is passed when no providers are enabled. */ ?>" />

Screenshots or screencast

See the Issue for the before.

Note that in the recording the Session token changes, but the metadata remains.

Screen.Recording.2023-05-30.at.3.25.00.pm.mov

Changelog Entry

N/A - Fix for an unreleased change: #528

Copy link
Member

@iandunn iandunn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good and it works in my tests 👍🏻

class-two-factor-core.php Show resolved Hide resolved
@dd32 dd32 merged commit 98830a9 into WordPress:master Jun 1, 2023
@kasparsd kasparsd mentioned this pull request Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

is_current_user_session_two_factor() returns false after changing password
3 participants