Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a sniff for "Restricted Filters" #231

Merged
merged 10 commits into from
Oct 18, 2018
4 changes: 4 additions & 0 deletions WordPress-VIP-Go/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@


<!-- Warnings and other things -->
<rule ref="WordPressVIPMinimum.Filters.RestrictedFilter.UploadMimes">
<type>warning</type>
<severity>10</severity>
GaryJones marked this conversation as resolved.
Show resolved Hide resolved
</rule>
<rule ref="WordPressVIPMinimum.VIP.RestrictedFunctions.dbDelta_dbdelta">
<type>warning</type>
<severity>7</severity>
Expand Down
12 changes: 6 additions & 6 deletions WordPressVIPMinimum/Sniffs/Filters/RestrictedFilterSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public function process( File $phpcsFile, $stackPtr ) {
true
);

$endHookPtr = $phpcsFile->findNext(
$endHookPtr = $phpcsFile->findNext(
T_COMMA,
$filterNamePtr,
null,
false,
null,
null,
true
);

Expand All @@ -82,11 +82,11 @@ public function process( File $phpcsFile, $stackPtr ) {
$filterNamePtr,
$endHookPtr,
false,
null,
null,
true
);
$concatenation = $concatPtr ? true: false;
if ( $concatenation ) {
$concatenation = $concatPtr ? true : false;
if ( $concatenation ) {
for ( $i = $filterNamePtr + 1; $i < $endHookPtr; $i++ ) {
if ( T_CONSTANT_ENCAPSED_STRING === $tokens[ $i ]['code'] ) {
$filterName .= $this->transformString( $tokens[ $i ]['content'] );
Expand All @@ -95,7 +95,7 @@ public function process( File $phpcsFile, $stackPtr ) {
}

if ( isset( $this->restrictedFilters[ $filterName ] ) && 'upload_mimes' === $filterName ) {
$phpcsFile->addWarning( 'Please ensure that the mimes being filtered do not include insecure types (e.g. SVG). Manual inspection required.', $stackPtr, 'UploadMimesRestrictedFilter' );
$phpcsFile->addWarning( 'Please ensure that the mimes being filtered do not include insecure types (e.g. SVG). Manual inspection required.', $stackPtr, 'UploadMimes' );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Unit test class for the Filters/RestrictedFilter sniff.
*

This comment was marked as resolved.

* @package VIPCS\WordPressVIPMinimum
*
*
* @since 0.4.0
*/
class RestrictedFilterUnitTest extends AbstractSniffUnitTest {
Expand Down