fix: correct the nonce argument in the version switch AJAX handlers - #494
Closed
TallblokeUK wants to merge 1 commit into
Closed
fix: correct the nonce argument in the version switch AJAX handlers#494TallblokeUK wants to merge 1 commit into
TallblokeUK wants to merge 1 commit into
Conversation
check_ajax_referer() reads its second argument as the name of the request key holding the nonce, but both handlers passed the nonce value itself. WordPress looked for $_REQUEST['<nonce value>'], found nothing, fell through to _ajax_nonce and _wpnonce which the front end does not send, and ended up verifying an empty string. Both handlers therefore rejected every request with a 403, including requests carrying a valid nonce, so Switch Version and Refresh Available Versions did nothing. Passing the key name lets a valid nonce through while an invalid one is still rejected.
Contributor
Author
|
Superseded by #506, which targets |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Switching or rolling back the plugin version does nothing. Picking a version and clicking Switch Version shows "An error occurred."; Refresh Available Versions resets its own label without any message at all. Reproduced on a live site as well as locally.
check_ajax_referer( $action, $query_arg )treats$query_argas the name of the request key to read the nonce from. Both handlers passed the nonce's value there instead, so WordPress looked for$_REQUEST['<the nonce value>'], fell through to_ajax_nonceand_wpnonce— neither of which the front end sends — and verified an empty string. Every request was rejected, valid nonce or not.Promotion_Base::dismiss_promotion_ajax_handler()already does this correctly withcheck_ajax_referer( self::AJAX_ACTION, 'nonce' ), which is the form used here.Testing
Against
admin-ajax.phpas a logged-in admin:403200 success403403403403403The switch case was exercised with an empty
target_version, so the request passes the nonce and capability checks and stops at validation — proving the gate opens without installing anything.Driven through the real UI afterwards: the dropdown populates with all 62 versions from wordpress.org and both buttons respond. phpcs clean.
Note this sits behind Settings → Debug → Enable version change, which is off by default, so only people who switched it on will have hit it.