Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Rector\PHPUnit\CodeQuality\Rector\Class_\RemoveDataProviderParamKeysRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\Renaming\Rector\ConstFetch\RenameConstantRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector;
Expand Down Expand Up @@ -205,4 +206,7 @@
// keep '\\' prefix string on string '\Foo\Bar'
StringClassNameToClassConstantRector::SHOULD_KEEP_PRE_SLASH => true,
])
->withConfiguredRule(RenameConstantRector::class, [
'FILTER_DEFAULT' => 'FILTER_UNSAFE_RAW',
])
->withCodeQualityLevel(34);
8 changes: 4 additions & 4 deletions system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,10 @@ public function getJsonVar($index = null, bool $assoc = false, ?int $filter = nu
return null;
}

$filter ??= FILTER_DEFAULT;
$filter ??= FILTER_UNSAFE_RAW;
$flags = is_array($flags) ? $flags : (is_numeric($flags) ? (int) $flags : 0);

if ($filter !== FILTER_DEFAULT
if ($filter !== FILTER_UNSAFE_RAW
|| (
(is_numeric($flags) && $flags !== 0)
|| is_array($flags) && $flags !== []
Expand Down Expand Up @@ -656,12 +656,12 @@ public function getRawInputVar($index = null, ?int $filter = null, $flags = null
[$output, $data] = [$data, null];
}

$filter ??= FILTER_DEFAULT;
$filter ??= FILTER_UNSAFE_RAW;
$flags = is_array($flags) ? $flags : (is_numeric($flags) ? (int) $flags : 0);

if (is_array($output)
&& (
$filter !== FILTER_DEFAULT
$filter !== FILTER_UNSAFE_RAW
|| (
(is_numeric($flags) && $flags !== 0)
|| is_array($flags) && $flags !== []
Expand Down
4 changes: 2 additions & 2 deletions system/HTTP/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function fetchGlobal(string $name, $index = null, ?int $filter = null, $f
}

// Null filters cause null values to return.
$filter ??= FILTER_DEFAULT;
$filter ??= FILTER_UNSAFE_RAW;
$flags = is_array($flags) ? $flags : (is_numeric($flags) ? (int) $flags : 0);

// Return all values when $index is null
Expand Down Expand Up @@ -312,7 +312,7 @@ public function fetchGlobal(string $name, $index = null, ?int $filter = null, $f

if (is_array($value)
&& (
$filter !== FILTER_DEFAULT
$filter !== FILTER_UNSAFE_RAW
|| (
(is_numeric($flags) && $flags !== 0)
|| is_array($flags) && $flags !== []
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/cookie_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function get_cookie($index, bool $xssClean = false, ?string $prefix = '')
}

$request = service('request');
$filter = $xssClean ? FILTER_SANITIZE_FULL_SPECIAL_CHARS : FILTER_DEFAULT;
$filter = $xssClean ? FILTER_SANITIZE_FULL_SPECIAL_CHARS : FILTER_UNSAFE_RAW;

return $request->getCookie($prefix . $index, $filter);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/system/HTTP/IncomingRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,13 @@ public static function provideCanGrabGetRawInputVar(): iterable
null,
null,
],
[
'username=admin001&role=administrator&usepass=0',
'username',
'admin001',
null,
FILTER_UNSAFE_RAW,
],
[
'username=admin001&role=administrator&usepass=0',
['role', 'usepass'],
Expand Down
Loading