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
6 changes: 5 additions & 1 deletion WordPress/Sniffs/Security/NonceVerificationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ private function has_nonce_check( $stackPtr, array $cache_keys, $allow_nonce_aft
continue;
}

$content_lc = \strtolower( $this->tokens[ $i ]['content'] );

// If this is one of the nonce verification functions, we can bail out.
if ( isset( $this->nonceVerificationFunctions[ $this->tokens[ $i ]['content'] ] ) ) {
if ( isset( $this->nonceVerificationFunctions[ $content_lc ] ) ) {
/*
* Now, make sure it is a call to a global function.
*/
Expand Down Expand Up @@ -416,6 +418,8 @@ protected function mergeFunctionLists() {
$this->nonceVerificationFunctions
);

$this->nonceVerificationFunctions = array_change_key_case( $this->nonceVerificationFunctions );

$this->addedCustomNonceFunctions = $this->customNonceVerificationFunctions;
}
}
Expand Down
38 changes: 38 additions & 0 deletions WordPress/Tests/Security/NonceVerificationUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,41 @@ enum MyEnum {
echo $_POST['foo']; // OK.
}
}

// Good, has a nonce check. Ensure the check is case-insensitive as function names are case-insensitive in PHP.
function ajax_process() {
CHECK_AJAX_REFERER( 'something' );

update_post_meta( (int) $_POST['id'], 'a_key', $_POST['a_value'] );
}

// phpcs:set WordPress.Security.NonceVerification customNonceVerificationFunctions[] MIXED_case_NAME
function non_ascii_characters() {
MIXED_case_NAME( $_POST['something'] ); // Passing $_POST to ensure the sniff bails correctly for variables inside the nonce verification function.

update_post_meta( (int) $_POST['id'], 'a_key', $_POST['a_value'] );
}
// phpcs:set WordPress.Security.NonceVerification customNonceVerificationFunctions[]

/*
* Test case handling of non-ASCII characters in function names.
*/
// phpcs:set WordPress.Security.NonceVerification customNonceVerificationFunctions[] déjà_vu
function same_function_same_case() {
déjà_vu( 'something' ); // Ok.

update_post_meta( (int) $_POST['id'], 'a_key', $_POST['a_value'] );
}

function same_function_different_case() {
DéJà_VU( 'something' ); // Ok.

update_post_meta( (int) $_POST['id'], 'a_key', $_POST['a_value'] );
}

function different_function_name() {
dÉjÀ_vu( 'something' ); // Bad, dÉjÀ_vu() and déjà_vu() are NOT the same function.

update_post_meta( (int) $_POST['id'], 'a_key', $_POST['a_value'] );
}
// phpcs:set WordPress.Security.NonceVerification customNonceVerificationFunctions[]
1 change: 1 addition & 0 deletions WordPress/Tests/Security/NonceVerificationUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function getErrorList( $testFile = '' ) {
453 => 1,
470 => 1,
478 => 1,
524 => 2,
);

case 'NonceVerificationUnitTest.2.inc':
Expand Down