Skip to content

Commit 824bb1b

Browse files
committed
Security/PHPFilterFunctions: document unsupported PHP feature
The `$options` parameter for `filter_var_array()` and `filter_input_array()` can take either an integer (filter constant) or an array with options, which could include an option setting the filter constant. At this time, this sniff does not handle an array with options being passed to these functions. Adding support for this will make the sniff much more complicated as PHP supports multiple array formats. Additionally, if the `$options` parameter is passed as an array, the likelyhood that the array is passed in as a variable increases exponentially, so then the next problem would be finding the variable definition and analysing that. All in all, this is a rabbit hole without end. Refs: * https://www.php.net/manual/en/function.filter-var-array.php * https://www.php.net/manual/en/function.filter-input-array.php
1 parent 4febbf3 commit 824bb1b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

WordPressVIPMinimum/Sniffs/Security/PHPFilterFunctionsSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
/**
1717
* This sniff ensures that proper sanitization is occurring when PHP's filter_* functions are used.
1818
*
19+
* {@internal The $options parameter for filter_var_array() and filter_input_array() can take either an
20+
* integer (filter constant) or an array with options, which could include an option setting the filter constant.
21+
* At this time, this sniff does not handle an array with options being passed.}
22+
*
1923
* @since 0.4.0
2024
*/
2125
class PHPFilterFunctionsSniff extends AbstractFunctionParameterSniff {

WordPressVIPMinimum/Tests/Security/PHPFilterFunctionsUnitTest.inc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,22 @@ filter_input(INPUT_GET, ...$params);
7979
trim(filter_input(INPUT_GET, ...$params));
8080
// ... but only ignore unpacking if done at the correct nesting level.
8181
filter_input(INPUT_GET, $obj->getVarname(...$params)); // Missing $filter parameter.
82+
83+
// False negatives: $options arrays are currently not (yet) supported by this sniff.
84+
// See: https://www.php.net/manual/en/function.filter-var-array.php and https://www.php.net/manual/en/function.filter-input-array.php
85+
filter_var_array(
86+
$array,
87+
array('keyA' => FILTER_DEFAULT), // This filter ID does nothing.
88+
);
89+
filter_input_array(
90+
$array,
91+
[
92+
'keyA' => [
93+
'filter' => FILTER_UNSAFE_RAW, // This filter ID does nothing.
94+
'flags' => FILTER_FORCE_ARRAY,
95+
],
96+
'keyB' => [
97+
'filter' => FILTER_SANITIZE_ENCODED,
98+
],
99+
]
100+
);

0 commit comments

Comments
 (0)