Skip to content

Commit e953ac7

Browse files
committed
Security/PHPFilterFunctions: prevent some false positives
The `'raw'` key in the parameter arrays returned from the `PassedParameters` class contains - as per the name - the _raw_ contents of the parameter. Since PHPCSUtils 1.0.0-alpha4, the return array also contain a `'clean'` index, which contains the contents of the parameter cleaned of comments. By switching to using that key, some false positives get prevented. Includes unit tests demonstrating the issue and safeguarding the fix.
1 parent dafc562 commit e953ac7

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

WordPressVIPMinimum/Sniffs/Security/PHPFilterFunctionsSniff.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
6767
$this->phpcsFile->addWarning( $message, $stackPtr, 'MissingThirdParameter', $data );
6868
}
6969

70-
if ( isset( $parameters[3], $this->restricted_filters[ $parameters[3]['raw'] ] ) ) {
70+
if ( isset( $parameters[3], $this->restricted_filters[ $parameters[3]['clean'] ] ) ) {
7171
$message = 'Please use an appropriate filter to sanitize, as "%s" does no filtering, see: http://php.net/manual/en/filter.filters.sanitize.php.';
72-
$data = [ $parameters[3]['raw'] ];
72+
$data = [ $parameters[3]['clean'] ];
7373
$this->phpcsFile->addWarning( $message, $stackPtr, 'RestrictedFilter', $data );
7474
}
7575
} else {
@@ -79,9 +79,9 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
7979
$this->phpcsFile->addWarning( $message, $stackPtr, 'MissingSecondParameter', $data );
8080
}
8181

82-
if ( isset( $parameters[2], $this->restricted_filters[ $parameters[2]['raw'] ] ) ) {
82+
if ( isset( $parameters[2], $this->restricted_filters[ $parameters[2]['clean'] ] ) ) {
8383
$message = 'Please use an appropriate filter to sanitize, as "%s" does no filtering, see http://php.net/manual/en/filter.filters.sanitize.php.';
84-
$data = [ $parameters[2]['raw'] ];
84+
$data = [ $parameters[2]['clean'] ];
8585
$this->phpcsFile->addWarning( $message, $stackPtr, 'RestrictedFilter', $data );
8686
}
8787
}

WordPressVIPMinimum/Tests/Security/PHPFilterFunctionsUnitTest.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $incorrect_but_ok = filter_input();
4343
*/
4444
filter_input( INPUT_GET, 'foo' ); // Missing third parameter.
4545
\filter_input( INPUT_GET, 'foo', FILTER_DEFAULT ); // This filter ID does nothing.
46-
filter_input( INPUT_GET, "foo", FILTER_UNSAFE_RAW ,); // This filter ID does nothing.
46+
filter_input( INPUT_GET, "foo", FILTER_UNSAFE_RAW /* comment */ ,); // This filter ID does nothing.
4747

4848
filter_var( $url ); // Missing second parameter.
4949
Filter_Var( $url, FILTER_DEFAULT ); // This filter ID does nothing.

0 commit comments

Comments
 (0)