[HttpFoundation] fixed error when an IP in the X-Forwarded-For HTTP header contains a port
This commit is contained in:
parent
f68b7c7d9d
commit
60ad382684
@ -793,6 +793,11 @@ class Request
|
|||||||
|
|
||||||
// Eliminate all IPs from the forwarded IP chain which are trusted proxies
|
// Eliminate all IPs from the forwarded IP chain which are trusted proxies
|
||||||
foreach ($clientIps as $key => $clientIp) {
|
foreach ($clientIps as $key => $clientIp) {
|
||||||
|
// Remove port on IPv4 address (unfortunately, it does happen)
|
||||||
|
if (preg_match('{((?:\d+\.){3}\d+)\:\d+}', $clientIp, $match)) {
|
||||||
|
$clientIps[$key] = $clientIp = $match[1];
|
||||||
|
}
|
||||||
|
|
||||||
if (IpUtils::checkIp($clientIp, self::$trustedProxies)) {
|
if (IpUtils::checkIp($clientIp, self::$trustedProxies)) {
|
||||||
unset($clientIps[$key]);
|
unset($clientIps[$key]);
|
||||||
}
|
}
|
||||||
|
@ -884,6 +884,9 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|||||||
array(array('3620:0:1cfe:face:b00c::3'), '1620:0:1cfe:face:b00c::3', '3620:0:1cfe:face:b00c::3,2620:0:1cfe:face:b00c::3', array('1620:0:1cfe:face:b00c::3', '2620:0:1cfe:face:b00c::3')),
|
array(array('3620:0:1cfe:face:b00c::3'), '1620:0:1cfe:face:b00c::3', '3620:0:1cfe:face:b00c::3,2620:0:1cfe:face:b00c::3', array('1620:0:1cfe:face:b00c::3', '2620:0:1cfe:face:b00c::3')),
|
||||||
// multiple forwarded for with remote IPv4 addr and some reverse proxies trusted but in the middle
|
// multiple forwarded for with remote IPv4 addr and some reverse proxies trusted but in the middle
|
||||||
array(array('2620:0:1cfe:face:b00c::3', '4620:0:1cfe:face:b00c::3'), '1620:0:1cfe:face:b00c::3', '4620:0:1cfe:face:b00c::3,3620:0:1cfe:face:b00c::3,2620:0:1cfe:face:b00c::3', array('1620:0:1cfe:face:b00c::3', '3620:0:1cfe:face:b00c::3')),
|
array(array('2620:0:1cfe:face:b00c::3', '4620:0:1cfe:face:b00c::3'), '1620:0:1cfe:face:b00c::3', '4620:0:1cfe:face:b00c::3,3620:0:1cfe:face:b00c::3,2620:0:1cfe:face:b00c::3', array('1620:0:1cfe:face:b00c::3', '3620:0:1cfe:face:b00c::3')),
|
||||||
|
|
||||||
|
// client IP with port
|
||||||
|
array(array('88.88.88.88'), '127.0.0.1', '88.88.88.88:12345, 127.0.0.1', array('127.0.0.1')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user