Skip to content

Commit

Permalink
Don't process 2FA attempts unless it's a post request.
Browse files Browse the repository at this point in the history
  • Loading branch information
dd32 committed Feb 27, 2023
1 parent f0b2205 commit b1f6adb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -949,9 +949,10 @@ public static function is_user_rate_limited( $user ) {
* @since 0.1-dev
*/
public static function login_form_validate_2fa() {
$wp_auth_id = ! empty( $_REQUEST['wp-auth-id'] ) ? absint( $_REQUEST['wp-auth-id'] ) : 0;
$nonce = ! empty( $_REQUEST['wp-auth-nonce'] ) ? wp_unslash( $_REQUEST['wp-auth-nonce'] ) : '';
$provider = ! empty( $_REQUEST['provider'] ) ? wp_unslash( $_REQUEST['provider'] ) : false;
$wp_auth_id = ! empty( $_REQUEST['wp-auth-id'] ) ? absint( $_REQUEST['wp-auth-id'] ) : 0;
$nonce = ! empty( $_REQUEST['wp-auth-nonce'] ) ? wp_unslash( $_REQUEST['wp-auth-nonce'] ) : '';
$provider = ! empty( $_REQUEST['provider'] ) ? wp_unslash( $_REQUEST['provider'] ) : false;
$is_post_request = ( 'POST' === strtoupper( $_SERVER['REQUEST_METHOD'] ) );

if ( ! $wp_auth_id || ! $nonce ) {
return;
Expand Down Expand Up @@ -989,6 +990,17 @@ public static function login_form_validate_2fa() {
exit;
}

// If the form hasn't been submitted, just display the auth form.
if ( ! $is_post_request ) {
$login_nonce = self::create_login_nonce( $user->ID );
if ( ! $login_nonce ) {
wp_die( esc_html__( 'Failed to create a login nonce.', 'two-factor' ) );
}

self::login_html( $user, $login_nonce['key'], $_REQUEST['redirect_to'], '', $provider );
exit;
}

// Rate limit two factor authentication attempts.
if ( true === self::is_user_rate_limited( $user ) ) {
$time_delay = self::get_user_time_delay( $user );
Expand Down

0 comments on commit b1f6adb

Please sign in to comment.