Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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/Sniffs/Security/NonceVerificationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ private function set_cache( $filename, $start, $end, $nonce ) {
*/
protected function mergeFunctionLists() {
if ( $this->customNonceVerificationFunctions !== $this->addedCustomNonceFunctions ) {
$this->customNonceVerificationFunctions = array_map( 'strtolower', $this->customNonceVerificationFunctions );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you changing the user-provided value ? instead of changing the merge result $this->nonceVerificationFunctions ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had in my mind that the user-provided value is the only one that required change, and that is why I opted to change it. After seeing your question, I imagine you are suggesting changing $this->nonceVerificationFunctions to ensure the sniff behaves correctly if, in the future, a new function is added to this property without all lowercase letters, and also to ensure it behaves correctly for sniffs extending this one. Is that the case?

I went ahead and pushed a new commit changing $this->nonceVerificationFunctions instead of $this->customNonceVerificationFunctions.

$this->nonceVerificationFunctions = RulesetPropertyHelper::merge_custom_array(
$this->customNonceVerificationFunctions,
$this->nonceVerificationFunctions
Expand Down
31 changes: 31 additions & 0 deletions WordPress/Tests/Security/NonceVerificationUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,34 @@ function ajax_process() {

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
Loading