From 7815bbf3ea9bc46d80ec283a2bde40a92dde2e96 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 22 Apr 2011 15:42:07 +0200 Subject: [PATCH 1/9] [HttpFoundation] refactor Request::getClientIp test --- .../Component/HttpFoundation/RequestTest.php | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php b/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php index 019fa215f0..2a3c10ba46 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php @@ -434,21 +434,36 @@ class RequestTest extends \PHPUnit_Framework_TestCase $this->assertEquals('PURGE', $request->getMethod(), '->getMethod() returns the method from _method if defined and POST'); } - public function testGetClientIp() + /** + * @dataProvider testGetClientIpProvider + */ + public function testGetClientIp($expected, $proxy, $remoteAddr, $httpClientIp, $httpForwardedFor) { $request = new Request; $this->assertEquals('', $request->getClientIp()); $this->assertEquals('', $request->getClientIp(true)); - $request->initialize(array(), array(), array(), array(), array(), array('REMOTE_ADDR' => '88.88.88.88')); - $this->assertEquals('88.88.88.88', $request->getClientIp()); - $request->initialize(array(), array(), array(), array(), array(), array('REMOTE_ADDR' => '127.0.0.1', 'HTTP_CLIENT_IP' => '88.88.88.88')); - $this->assertEquals('127.0.0.1', $request->getClientIp()); - $request->initialize(array(), array(), array(), array(), array(), array('REMOTE_ADDR' => '127.0.0.1', 'HTTP_CLIENT_IP' => '88.88.88.88')); - $this->assertEquals('88.88.88.88', $request->getClientIp(true)); - $request->initialize(array(), array(), array(), array(), array(), array('REMOTE_ADDR' => '127.0.0.1', 'HTTP_X_FORWARDED_FOR' => '88.88.88.88')); - $this->assertEquals('127.0.0.1', $request->getClientIp()); - $request->initialize(array(), array(), array(), array(), array(), array('REMOTE_ADDR' => '127.0.0.1', 'HTTP_X_FORWARDED_FOR' => '88.88.88.88')); - $this->assertEquals('88.88.88.88', $request->getClientIp(true)); + + $server = array('REMOTE_ADDR' => $remoteAddr); + if (!is_null($httpClientIp)) { + $server['HTTP_CLIENT_IP'] = $httpClientIp; + } + if (!is_null($httpForwardedFor)) { + $server['HTTP_X_FORWARDED_FOR'] = $httpForwardedFor; + } + + $request->initialize(array(), array(), array(), array(), array(), $server); + $this->assertEquals($expected, $request->getClientIp($proxy)); + } + + public function testGetClientIpProvider() + { + return array( + array('88.88.88.88', false, '88.88.88.88', null, null), + array('127.0.0.1', false, '127.0.0.1', '88.88.88.88', null), + array('88.88.88.88', true, '127.0.0.1', '88.88.88.88', null), + array('127.0.0.1', false, '127.0.0.1', null, '88.88.88.88'), + array('88.88.88.88', true, '127.0.0.1', null, '88.88.88.88'), + ); } public function testGetContentWorksTwiceInDefaultMode() From 18e9268112c9a50d30d211e4cbd85fcab16dd62c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 22 Apr 2011 15:47:31 +0200 Subject: [PATCH 2/9] [HttpFoundation] test Request::create with an IP as host name --- .../Tests/Component/HttpFoundation/RequestTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php b/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php index 2a3c10ba46..f1fd0d0f72 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php @@ -81,6 +81,14 @@ class RequestTest extends \PHPUnit_Framework_TestCase $this->assertEquals(90, $request->getPort()); $this->assertTrue($request->isSecure()); + $request = Request::create('https://127.0.0.1:90/foo'); + $this->assertEquals('https://127.0.0.1:90/foo', $request->getUri()); + $this->assertEquals('/foo', $request->getPathInfo()); + $this->assertEquals('127.0.0.1', $request->getHost()); + $this->assertEquals('127.0.0.1:90', $request->getHttpHost()); + $this->assertEquals(90, $request->getPort()); + $this->assertTrue($request->isSecure()); + $json = '{"jsonrpc":"2.0","method":"echo","id":7,"params":["Hello World"]}'; $request = Request::create('http://example.com/jsonrpc', 'POST', array(), array(), array(), array(), $json); $this->assertEquals($json, $request->getContent()); From 82699c5a9854f724a095bfd161d56c70409c0269 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 22 Apr 2011 16:28:15 +0200 Subject: [PATCH 3/9] [HttpFoundation] add IPv6 support to Request --- src/Symfony/Component/HttpFoundation/Request.php | 4 ++-- .../Tests/Component/HttpFoundation/RequestTest.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 466236da67..26a599b73b 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -543,9 +543,9 @@ class Request } // Remove port number from host - $elements = explode(':', $host); + $host = preg_replace('/:(\d+)$/', '', $host); - return trim($elements[0]); + return trim($host); } public function setMethod($method) diff --git a/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php b/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php index f1fd0d0f72..1aef59ad51 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php @@ -89,6 +89,14 @@ class RequestTest extends \PHPUnit_Framework_TestCase $this->assertEquals(90, $request->getPort()); $this->assertTrue($request->isSecure()); + $request = Request::create('https://[::1]:90/foo'); + $this->assertEquals('https://[::1]:90/foo', $request->getUri()); + $this->assertEquals('/foo', $request->getPathInfo()); + $this->assertEquals('[::1]', $request->getHost()); + $this->assertEquals('[::1]:90', $request->getHttpHost()); + $this->assertEquals(90, $request->getPort()); + $this->assertTrue($request->isSecure()); + $json = '{"jsonrpc":"2.0","method":"echo","id":7,"params":["Hello World"]}'; $request = Request::create('http://example.com/jsonrpc', 'POST', array(), array(), array(), array(), $json); $this->assertEquals($json, $request->getContent()); @@ -471,6 +479,8 @@ class RequestTest extends \PHPUnit_Framework_TestCase array('88.88.88.88', true, '127.0.0.1', '88.88.88.88', null), array('127.0.0.1', false, '127.0.0.1', null, '88.88.88.88'), array('88.88.88.88', true, '127.0.0.1', null, '88.88.88.88'), + array('::1', false, '::1', null, null), + array('2620:0:1cfe:face:b00c::3', true, '::1', '2620:0:1cfe:face:b00c::3', null), ); } From afcdbf8b79757e671ae2a37013ebd2f3c3581bf3 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 22 Apr 2011 16:28:55 +0200 Subject: [PATCH 4/9] [Validator] add IPv6 support to UrlValidator --- .../Component/Validator/Constraints/UrlValidator.php | 10 +++++++--- .../Validator/Constraints/UrlValidatorTest.php | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index d10cb00cca..2ed9544285 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -20,9 +20,13 @@ class UrlValidator extends ConstraintValidator const PATTERN = '~^ (%s):// # protocol ( - ([a-z0-9-]+\.)+[a-z]{2,6} # a domain name - | # or - \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # a IP address + ([a-z0-9-]+\.)+[a-z]{2,6} # a domain name + | # or + \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # a IP address + | # or + \[ + [0-9a-fA-F]{0,4}(:[0-9a-fA-F]{0,4}){1,5}((:[0-9a-fA-F]{0,4}){1,2}|:([\d\.]+)) + \] # a IPv6 address ) (:[0-9]+)? # a port (optional) (/?|/\S+) # a /, nothing or a / with something diff --git a/tests/Symfony/Tests/Component/Validator/Constraints/UrlValidatorTest.php b/tests/Symfony/Tests/Component/Validator/Constraints/UrlValidatorTest.php index a41261e4e4..a796ee0992 100755 --- a/tests/Symfony/Tests/Component/Validator/Constraints/UrlValidatorTest.php +++ b/tests/Symfony/Tests/Component/Validator/Constraints/UrlValidatorTest.php @@ -57,6 +57,8 @@ class UrlValidatorTest extends \PHPUnit_Framework_TestCase array('http://www.symfony.com/'), array('http://127.0.0.1/'), array('http://127.0.0.1:80/'), + array('http://[::1]/'), + array('http://[::1]:80/'), ); } From e5b923a0ecb5dd0bb0879e35a304af404f73bff5 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 22 Apr 2011 16:30:50 +0200 Subject: [PATCH 5/9] [Validator] use full iPv6 regex it was taken from: https://github.com/strattg/ipv6-address-test/blob/master/Tests/Rfc3986RegexTest.php --- src/Symfony/Component/Validator/Constraints/UrlValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index 2ed9544285..c95de8c366 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -25,7 +25,7 @@ class UrlValidator extends ConstraintValidator \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # a IP address | # or \[ - [0-9a-fA-F]{0,4}(:[0-9a-fA-F]{0,4}){1,5}((:[0-9a-fA-F]{0,4}){1,2}|:([\d\.]+)) + (?:(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-fA-F]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1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{1,4})):){0,4}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,5}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,6}(?:(?:[0-9a-fA-F]{1,4})))?::)))) \] # a IPv6 address ) (:[0-9]+)? # a port (optional) From 5a80c2ff17750e047abc8f9ba548d55570f41e4b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 22 Apr 2011 17:06:28 +0200 Subject: [PATCH 6/9] [HttpFoundation] refactor RequestMatcherTest to use dataProvider --- .../HttpFoundation/RequestMatcherTest.php | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/Symfony/Tests/Component/HttpFoundation/RequestMatcherTest.php b/tests/Symfony/Tests/Component/HttpFoundation/RequestMatcherTest.php index 167e03ccbf..016aaf7a38 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/RequestMatcherTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/RequestMatcherTest.php @@ -16,19 +16,26 @@ use Symfony\Component\HttpFoundation\Request; class RequestMatcherTest extends \PHPUnit_Framework_TestCase { - public function testIp() + /** + * @dataProvider testIpProvider + */ + public function testIp($matches, $remoteAddr, $cidr) { + $request = Request::create('', 'get', array(), array(), array(), array('REMOTE_ADDR' => $remoteAddr)); + $matcher = new RequestMatcher(); + $matcher->matchIp($cidr); - $matcher->matchIp('192.168.1.1/1'); - $request = Request::create('', 'get', array(), array(), array(), array('REMOTE_ADDR' => '192.168.1.1')); - $this->assertTrue($matcher->matches($request)); + $this->assertEquals($matches, $matcher->matches($request)); + } - $matcher->matchIp('192.168.1.0/24'); - $this->assertTrue($matcher->matches($request)); - - $matcher->matchIp('1.2.3.4/1'); - $this->assertFalse($matcher->matches($request)); + public function testIpProvider() + { + return array( + array(true, '192.168.1.1', '192.168.1.1/1'), + array(true, '192.168.1.1', '192.168.1.0/24'), + array(false, '192.168.1.1', '1.2.3.4/1'), + ); } public function testMethod() From 9ae5023a7058f644bc37bfc2623487f6a78986a4 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 22 Apr 2011 17:37:22 +0200 Subject: [PATCH 7/9] [HttpFoundation] IPv6 support for RequestMatcher --- .../HttpFoundation/RequestMatcher.php | 33 +++++++++++++++++++ .../HttpFoundation/RequestMatcherTest.php | 2 ++ 2 files changed, 35 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/RequestMatcher.php b/src/Symfony/Component/HttpFoundation/RequestMatcher.php index 9b1e476461..7b216546e7 100644 --- a/src/Symfony/Component/HttpFoundation/RequestMatcher.php +++ b/src/Symfony/Component/HttpFoundation/RequestMatcher.php @@ -121,6 +121,16 @@ class RequestMatcher implements RequestMatcherInterface } protected function checkIp($ip) + { + // IPv6 address + if (false !== strpos($ip, ':')) { + return $this->checkIp6($ip); + } else { + return $this->checkIp4($ip); + } + } + + protected function checkIp4($ip) { if (false !== strpos($this->ip, '/')) { list($address, $netmask) = explode('/', $this->ip); @@ -135,4 +145,27 @@ class RequestMatcher implements RequestMatcherInterface return 0 === substr_compare(sprintf('%032b', ip2long($ip)), sprintf('%032b', ip2long($address)), 0, $netmask); } + + /** + * @author David Soria Parra + * @see https://github.com/dsp/v6tools + */ + protected function checkIp6($ip) + { + list($address, $netmask) = explode('/', $this->ip); + + $bytes_addr = unpack("n*", inet_pton($address)); + $bytes_test = unpack("n*", inet_pton($ip)); + + for ($i = 1; $i <= ceil($netmask / 16); $i++) { + $left = $netmask - 16 * ($i-1); + $left = ($left <= 16) ?: 16; + $mask = ~(0xffff >> $left) & 0xffff; + if (($bytes_addr[$i] & $mask) != ($bytes_test[$i] & $mask)) { + return false; + } + } + + return true; + } } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/RequestMatcherTest.php b/tests/Symfony/Tests/Component/HttpFoundation/RequestMatcherTest.php index 016aaf7a38..d24eb54368 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/RequestMatcherTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/RequestMatcherTest.php @@ -35,6 +35,8 @@ class RequestMatcherTest extends \PHPUnit_Framework_TestCase array(true, '192.168.1.1', '192.168.1.1/1'), array(true, '192.168.1.1', '192.168.1.0/24'), array(false, '192.168.1.1', '1.2.3.4/1'), + array(true, '2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'), + array(false, '2a00:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'), ); } From 51d12758a02c2827eb6c17afc908fc9862cc50fb Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 22 Apr 2011 18:37:20 +0200 Subject: [PATCH 8/9] minor adjustments suggested by vicb --- src/Symfony/Component/HttpFoundation/Request.php | 2 +- src/Symfony/Component/Validator/Constraints/UrlValidator.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 26a599b73b..a4e5dd9ebe 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -543,7 +543,7 @@ class Request } // Remove port number from host - $host = preg_replace('/:(\d+)$/', '', $host); + $host = preg_replace('/:\d+$/', '', $host); return trim($host); } diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index c95de8c366..2840cbb9f9 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -25,7 +25,7 @@ class UrlValidator extends ConstraintValidator \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # a IP address | # or \[ - (?:(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-fA-F]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,1}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,2}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){2})(?:(?:(?:(?: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[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,4}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,5}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::)))) \] # a IPv6 address ) (:[0-9]+)? # a port (optional) From 041a2e9d839b5536b21d2209defd7e60a148ea59 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 22 Apr 2011 22:20:12 +0200 Subject: [PATCH 9/9] [HttpFoundation] minor optimization --- src/Symfony/Component/HttpFoundation/RequestMatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/RequestMatcher.php b/src/Symfony/Component/HttpFoundation/RequestMatcher.php index 7b216546e7..7353692143 100644 --- a/src/Symfony/Component/HttpFoundation/RequestMatcher.php +++ b/src/Symfony/Component/HttpFoundation/RequestMatcher.php @@ -157,7 +157,7 @@ class RequestMatcher implements RequestMatcherInterface $bytes_addr = unpack("n*", inet_pton($address)); $bytes_test = unpack("n*", inet_pton($ip)); - for ($i = 1; $i <= ceil($netmask / 16); $i++) { + for ($i = 1, $ceil = ceil($netmask / 16); $i <= $ceil; $i++) { $left = $netmask - 16 * ($i-1); $left = ($left <= 16) ?: 16; $mask = ~(0xffff >> $left) & 0xffff;