WordPress / two-factor

Two-Factor Authentication for WordPress.
https://wordpress.org/plugins/two-factor/
GNU General Public License v2.0
724 stars 151 forks source link

Revalidation required when no providers enabled #565

Closed iandunn closed 1 year ago

iandunn commented 1 year ago

Describe the bug

If you disable all providers, you're still required to revalidate. You can't enable any providers until you do, but you get a fatal error when you try.

Screenshot 2023-05-12 at 3 08 07 PM

Uncaught Error: Call to a member function get_key() on null in two-factor/class-two-factor-core.php on line 742

Introduced in #529. I missed this during testing, but @adamwoodnz discovered it in https://github.com/WordPress/wporg-two-factor/issues/160. His PR https://github.com/WordPress/wporg-two-factor/pull/161/ would fix downstream, but it looks like the root cause is located here.

Steps to Reproduce

  1. logout
  2. delete all _two_factor... usermeta for the user
  3. add this to an to muplugin to make testing easier
    add_filter( 'two_factor_revalidate_time', function() {
        return 30;
    } );
  4. login, then go to wp-admin/profile.php
  5. wait 30 seconds, and refresh. the Revalidate button will not appear, because you don't have a 2fa session. that's the correct behavior
  6. now enable the Dummy provider, and immediately disable it (before the 30 second revalidation period expires)
  7. wait 30 seconds for the period to expire, then reload profile.php again. The Revalidate button will appear, because the WP session data still indicates that it's a 2FA session. that's wrong, and prevents you from enabling any provider until you revalidate. if you try to revalidate, you get the fatal error.
iandunn commented 1 year ago

Fixed by #567