Skip to content

Commit

Permalink
Modify Request::getClientIp() to use IpUtils::checkIp()
Browse files Browse the repository at this point in the history
Adds the ability to use CIDR notation in the trusted proxy list
  • Loading branch information
lazyhammer authored and fabpot committed Apr 20, 2013
1 parent 79cadc4 commit ddc9e38
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,16 @@ public function getClientIps()

$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);
}
Expand Down

0 comments on commit ddc9e38

Please sign in to comment.