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

Require a nonce be present for revalidate POST requests. #575

Closed dd32 closed 1 year ago

dd32 commented 1 year ago

What?

Two-Factor includes a nonce during the validate_2fa callback, and while the fields are present in the POST request for the revalidate endpoint, it's not used.

Props @xknown for the report.

Why?

A nonce should be present on all POST requests that perform actions, to prevent potential CSRF attacks.

How?

Due to the revalidation occurring with an authenticated session, wp_create_nonce() is used to validate the request. The Two-Factor login_nonce functionality is not used, to ensure that the revalidate nonce can't be used to login a new session.

The nonce is ignored during GET requests for the revalidate endpoint.

The check could be changed to if ( ( $is_post_request || $nonce ) && ! wp_verify_nonce( $nonce .. ) ) { if required, but it seems more explicit to only require it for POST requests, as that's where it's actually protecting against an attack.

Testing Instructions

  1. Apply PR
  2. Login as normal.
  3. During revalidate, remove the wp-auth-nonce from the POST payload, ensure the request fails.
  4. Ensure revalidate succeeds with the wp-auth-nonce field.

Screenshots or screencast

Changelog Entry

N/A - Unreleased feature.