[HttpKernel] Fixed invalid REMOTE_ADDR in inline subrequest when configuring trusted proxy with subnet
This commit is contained in:
parent
81eb54eb78
commit
f657dd2444
@ -122,8 +122,7 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
$trustedProxies = Request::getTrustedProxies();
|
$server['REMOTE_ADDR'] = $this->resolveTrustedProxy();
|
||||||
$server['REMOTE_ADDR'] = $trustedProxies ? reset($trustedProxies) : '127.0.0.1';
|
|
||||||
|
|
||||||
unset($server['HTTP_IF_MODIFIED_SINCE']);
|
unset($server['HTTP_IF_MODIFIED_SINCE']);
|
||||||
unset($server['HTTP_IF_NONE_MATCH']);
|
unset($server['HTTP_IF_NONE_MATCH']);
|
||||||
@ -140,6 +139,17 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
|
|||||||
return $subRequest;
|
return $subRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function resolveTrustedProxy()
|
||||||
|
{
|
||||||
|
if (!$trustedProxies = Request::getTrustedProxies()) {
|
||||||
|
return '127.0.0.1';
|
||||||
|
}
|
||||||
|
|
||||||
|
$firstTrustedProxy = reset($trustedProxies);
|
||||||
|
|
||||||
|
return false !== ($i = strpos($firstTrustedProxy, '/')) ? substr($firstTrustedProxy, 0, $i) : $firstTrustedProxy;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -226,6 +226,25 @@ class InlineFragmentRendererTest extends TestCase
|
|||||||
Request::setTrustedProxies(array());
|
Request::setTrustedProxies(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testIpAddressOfRangedTrustedProxyIsSetAsRemote()
|
||||||
|
{
|
||||||
|
$expectedSubRequest = Request::create('/');
|
||||||
|
$expectedSubRequest->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
|
||||||
|
$expectedSubRequest->server->set('REMOTE_ADDR', '1.1.1.1');
|
||||||
|
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
|
||||||
|
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
|
||||||
|
|
||||||
|
Request::setTrustedProxies(array('1.1.1.1/24'));
|
||||||
|
|
||||||
|
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($expectedSubRequest));
|
||||||
|
|
||||||
|
$request = Request::create('/');
|
||||||
|
$request->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
|
||||||
|
$strategy->render('/', $request);
|
||||||
|
|
||||||
|
Request::setTrustedProxies(array());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Kernel expecting a request equals to $request
|
* Creates a Kernel expecting a request equals to $request
|
||||||
* Allows delta in comparison in case REQUEST_TIME changed by 1 second.
|
* Allows delta in comparison in case REQUEST_TIME changed by 1 second.
|
||||||
|
Reference in New Issue
Block a user