Skip to content

Commit c088b1b

Browse files
committed
Sniff::$unslashingSanitizingFunctions: add doubleval() and count()
While `doubleval()` is an alias of `floatval()` and shouldn't be used, for the purposes of the ValidatedSanitizedInput sniff, both functions should be recognized. And as `count()` doesn't actually access the data in the variable, but only counts the number of elements, it is also safe to use without unslashing/sanitizing the variable beforehand. Same goes for the `sizeof()` alias of `count()`. Includes unit tests. Fixes 1659
1 parent 8fa98f6 commit c088b1b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

WordPress/Sniff.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,13 @@ abstract class Sniff implements PHPCS_Sniff {
309309
protected $unslashingSanitizingFunctions = array(
310310
'absint' => true,
311311
'boolval' => true,
312+
'count' => true,
313+
'doubleval' => true,
312314
'floatval' => true,
313315
'intval' => true,
314316
'is_array' => true,
315317
'sanitize_key' => true,
318+
'sizeof' => true,
316319
);
317320

318321
/**

WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,12 @@ if ( isset( $_GET['unslash_check'] ) ) {
216216
$clean = sanitize_text_field( WP_Faker::wp_unslash( $_GET['unslash_check'] ) ); // Bad x1 - unslash.
217217
$clean = WP_Faker\sanitize_text_field( wp_unslash( $_GET['unslash_check'] ) ); // Bad x1 - sanitize.
218218
}
219+
220+
function test_more_safe_functions() {
221+
if ( ! isset( $_GET['test'] ) ) {
222+
return;
223+
}
224+
225+
$float = doubleval( $_GET['test'] ); // OK.
226+
$count = count( $_GET['test'] ); // Issue #1659; OK.
227+
}

0 commit comments

Comments
 (0)