Modify Request::getClientIp() to use IpUtils::checkIp()

Adds the ability to use CIDR notation in the trusted proxy list
This commit is contained in:
Dmitrii Chekaliuk 2013-03-08 22:49:38 +02:00 committed by Fabien Potencier
parent 79cadc437d
commit ddc9e3892f

View File

@ -688,7 +688,16 @@ class Request
$trustedProxies = !self::$trustedProxies ? array($ip) : self::$trustedProxies;
$ip = $clientIps[0];
$clientIps = array_values(array_diff($clientIps, $trustedProxies));
foreach ($clientIps as $key => $clientIp) {
foreach ($trustedProxies as $trustedProxy) {
if (IpUtils::checkIp($clientIp, $trustedProxy)) {
unset($clientIps[$key]);
continue 2;
}
}
}
return $clientIps ? array_reverse($clientIps) : array($ip);
}