Skip to content

Commit af937cc

Browse files
authored
Merge pull request #1680 from WordPress-Coding-Standards/feature/nonceverification-only-allow-global-functions
Sniff::has_nonce_check(): add `is_class_object_call()` and `is_token_namespaced()` checks
2 parents 854964b + d0f7084 commit af937cc

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

WordPress/Sniff.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,17 @@ protected function has_nonce_check( $stackPtr ) {
14571457

14581458
// If this is one of the nonce verification functions, we can bail out.
14591459
if ( isset( $this->nonceVerificationFunctions[ $tokens[ $i ]['content'] ] ) ) {
1460+
/*
1461+
* Now, make sure it is a call to a global function.
1462+
*/
1463+
if ( $this->is_class_object_call( $i ) === true ) {
1464+
continue;
1465+
}
1466+
1467+
if ( $this->is_token_namespaced( $i ) === true ) {
1468+
continue;
1469+
}
1470+
14601471
$last['nonce_check'] = $i;
14611472
return true;
14621473
}

WordPress/Tests/Security/NonceVerificationUnitTest.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,14 @@ function test_incorrect_use_in_type_test_functions() {
178178
return;
179179
}
180180
}
181+
182+
function fix_false_negatives_userland_method_same_name() {
183+
WP_Faker::check_ajax_referer( 'something' );
184+
$faker->check_admin_referer( 'something' );
185+
do_something( $_POST['abc'] ); // Bad.
186+
}
187+
188+
function fix_false_negatives_namespaced_function_same_name() {
189+
WP_Faker\SecurityBypass\wp_verify_nonce( 'something' );
190+
do_something( $_POST['abc'] ); // Bad.
191+
}

WordPress/Tests/Security/NonceVerificationUnitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public function getErrorList() {
4747
160 => 1,
4848
161 => 1,
4949
177 => 1,
50+
185 => 1,
51+
190 => 1,
5052
);
5153
}
5254

0 commit comments

Comments
 (0)