Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions WordPress/Sniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,8 @@ protected function has_nonce_check( $stackPtr ) {
$allow_nonce_after = false;
if ( $this->is_in_isset_or_empty( $stackPtr )
|| $this->is_in_type_test( $stackPtr )
|| $this->is_comparison( $stackPtr )
|| $this->is_in_array_comparison( $stackPtr )
) {
$allow_nonce_after = true;
}
Expand Down
37 changes: 37 additions & 0 deletions WordPress/Tests/Security/NonceVerificationUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,40 @@ function skip_over_nested_constructs_2() {
}
};
}

// Issue #1506
function allow_for_compare_before_noncecheck() {
if (
'newsletter_sign_up' === $_POST['action'] && // OK.
wp_verify_nonce( $_POST['newsletter_nonce'] )
) {}
}

// Issue #1114
function allow_for_nonce_check_within_switch() {
if ( ! isset( $_REQUEST['action'] ) ) {
return;
}

switch ( $_REQUEST['action'] ) { // OK.
case 'foo':
check_admin_referer( 'foo' );
break;
case 'bar':
check_admin_referer( 'bar' );
break;
}
}

function allow_for_array_compare_before_noncecheck() {
if ( array_search( array( 'subscribe', 'unsubscribe', $_POST['action'], true ) // OK.
&& wp_verify_nonce( $_POST['newsletter_nonce'] )
) {}
}

function allow_for_array_comparison_in_condition() {
if ( in_array( $_GET['action'], $valid_actions, true ) ) { // OK.
check_admin_referer( 'foo' );
foo();
}
}