8000 Hlepers::ipMatch() fixed warning when passed invalid IP address by hrach · Pull Request #122 · nette/http · GitHub
[go: up one dir, main page]

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
2 changes: 1 addition & 1 deletion src/Http/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function createHttpRequest(): Request
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$xForwardedForWithoutProxies = array_filter(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']), function ($ip) {
return !array_filter($this->proxies, function ($proxy) use ($ip) {
return Helpers::ipMatch(trim($ip), $proxy);
return filter_var(trim($ip), FILTER_VALIDATE_IP) !== FALSE && Helpers::ipMatch(trim($ip), $proxy);
});
});
$remoteAddr = trim(end($xForwardedForWithoutProxies));
Expand Down
4 changes: 2 additions & 2 deletions tests/Http/RequestFactory.proxy.x-forwarded.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ test(function () {
$_SERVER = [
'REMOTE_ADDR' => '10.0.0.2', //proxy2
'REMOTE_HOST' => 'proxy2',
'HTTP_X_FORWARDED_FOR' => '123.123.123.123, 172.16.0.1, 10.0.0.1',
'HTTP_X_FORWARDED_HOST' => 'fake, real, proxy1',
'HTTP_X_FORWARDED_FOR' => '123.123.123.123, not-ip.com, 172.16.0.1, 10.0.0.1',
'HTTP_X_FORWARDED_HOST' => 'fake, not-ip.com, real, proxy1',
];

$factory = new RequestFactory;
Expand Down
0