From c4da2d9892f04653798eaa42b097730aafc2d4d0 Mon Sep 17 00:00:00 2001 From: dened Date: Mon, 25 Mar 2013 11:05:20 +0400 Subject: [PATCH] [HttpFoundation] getClientIp is fixed. The getClientIp now returns ip of the earliest server in a proxy chain when all the servers in the chain are trusted proxies. Before this patch the getClientIp used to return null at such condition. Some appropriate tests are added. --- src/Symfony/Component/HttpFoundation/Request.php | 3 ++- src/Symfony/Component/HttpFoundation/Tests/RequestTest.php | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 6da6bc87ed..d1b22eed2d 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -677,9 +677,10 @@ class Request $clientIps[] = $ip; $trustedProxies = self::$trustProxy && !self::$trustedProxies ? array($ip) : self::$trustedProxies; + $ip = $clientIps[0]; $clientIps = array_diff($clientIps, $trustedProxies); - return array_pop($clientIps); + return $clientIps ? array_pop($clientIps) : $ip; } /** diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 38ae748da6..afb495c931 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -660,6 +660,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase { return array( array('88.88.88.88', false, '88.88.88.88', null, null), + array('88.88.88.88', true, '88.88.88.88', null, null), array('127.0.0.1', false, '127.0.0.1', null, null), array('::1', false, '::1', null, null), array('127.0.0.1', false, '127.0.0.1', '88.88.88.88', null), @@ -668,6 +669,8 @@ class RequestTest extends \PHPUnit_Framework_TestCase array('88.88.88.88', true, '123.45.67.89', '127.0.0.1, 87.65.43.21, 88.88.88.88', null), array('87.65.43.21', true, '123.45.67.89', '127.0.0.1, 87.65.43.21, 88.88.88.88', array('123.45.67.89', '88.88.88.88')), array('87.65.43.21', false, '123.45.67.89', '127.0.0.1, 87.65.43.21, 88.88.88.88', array('123.45.67.89', '88.88.88.88')), + array('88.88.88.88', true, '123.45.67.89', '88.88.88.88', array('123.45.67.89', '88.88.88.88')), + array('88.88.88.88', false, '123.45.67.89', '88.88.88.88', array('123.45.67.89', '88.88.88.88')), ); }