Require a nonce be present for revalidate POST requests. #575
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
wp-auth-nonce
from the POST payload, ensure the request fails.wp-auth-nonce
field.Screenshots or screencast
Changelog Entry
N/A - Unreleased feature.