Skip to content

Commit ca3d41f

Browse files
authored
Merge pull request #1687 from WordPress-Coding-Standards/feature/572-nonceverification-allow-for-wp_unslash
Sniff::has_nonce_check(): allow for unslashing a variable before nonce check
2 parents 19e45db + bb646b6 commit ca3d41f

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

WordPress/Sniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,7 @@ protected function has_nonce_check( $stackPtr ) {
14551455
|| $this->is_in_type_test( $stackPtr )
14561456
|| $this->is_comparison( $stackPtr )
14571457
|| $this->is_in_array_comparison( $stackPtr )
1458+
|| $this->is_in_function_call( $stackPtr, $this->unslashingFunctions ) !== false
14581459
) {
14591460
$allow_nonce_after = true;
14601461
}

WordPress/Tests/Security/NonceVerificationUnitTest.inc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,21 @@ function allow_for_array_comparison_in_condition() {
246246
foo();
247247
}
248248
}
249+
250+
# Issue #572.
251+
function allow_for_unslash_before_noncecheck_but_demand_noncecheck() {
252+
$var = wp_unslash( $_POST['foo'] ); // Bad.
253+
echo $var;
254+
}
255+
256+
function allow_for_unslash_before_noncecheck() {
257+
$var = stripslashes_from_strings_only( $_POST['foo'] ); // OK.
258+
wp_verify_nonce( $var );
259+
echo $var;
260+
}
261+
262+
function allow_for_unslash_in_sanitization() {
263+
$var = sanitize_text_field( wp_unslash( $_POST['foo'] ) ); // OK.
264+
wp_verify_nonce( $var );
265+
echo $var;
266+
}

WordPress/Tests/Security/NonceVerificationUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function getErrorList() {
5151
190 => 1,
5252
198 => 1,
5353
202 => 1,
54+
252 => 1,
5455
);
5556
}
5657

0 commit comments

Comments
 (0)