Skip to content

Commit a056e5a

Browse files
committed
Merge branch '2.5'
* 2.5: [2.3] Add missing development dependencies Fix @return docs on HttpCache::restoreResponseBody() [Finder] Escape location for regex searches Make sure HttpCache is a trusted proxy Conflicts: src/Symfony/Component/Form/composer.json
2 parents 68c690a + 53a3d19 commit a056e5a

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

HttpCache/HttpCache.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,12 @@ protected function forward(Request $request, $catch = false, Response $entry = n
479479
// is always called from the same process as the backend.
480480
$request->server->set('REMOTE_ADDR', '127.0.0.1');
481481

482+
// make sure HttpCache is a trusted proxy
483+
if (!in_array('127.0.0.1', $trustedProxies = Request::getTrustedProxies())) {
484+
$trustedProxies[] = '127.0.0.1';
485+
Request::setTrustedProxies($trustedProxies);
486+
}
487+
482488
// always a "master" request (as the real master request can be in cache)
483489
$response = $this->kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, $catch);
484490
// FIXME: we probably need to also catch exceptions if raw === true
@@ -619,8 +625,6 @@ protected function store(Request $request, Response $response)
619625
*
620626
* @param Request $request A Request instance
621627
* @param Response $response A Response instance
622-
*
623-
* @return Response A Response instance
624628
*/
625629
private function restoreResponseBody(Request $request, Response $response)
626630
{

Tests/HttpCache/HttpCacheTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,28 @@ public function testClientIpIsAlwaysLocalhostForForwardedRequests()
11421142
$this->assertEquals('127.0.0.1', $this->kernel->getBackendRequest()->server->get('REMOTE_ADDR'));
11431143
}
11441144

1145+
/**
1146+
* @dataProvider getTrustedProxyData
1147+
*/
1148+
public function testHttpCacheIsSetAsATrustedProxy(array $existing, array $expected)
1149+
{
1150+
Request::setTrustedProxies($existing);
1151+
1152+
$this->setNextResponse();
1153+
$this->request('GET', '/', array('REMOTE_ADDR' => '10.0.0.1'));
1154+
1155+
$this->assertEquals($expected, Request::getTrustedProxies());
1156+
}
1157+
1158+
public function getTrustedProxyData()
1159+
{
1160+
return array(
1161+
array(array(), array('127.0.0.1')),
1162+
array(array('10.0.0.2'), array('10.0.0.2', '127.0.0.1')),
1163+
array(array('10.0.0.2', '127.0.0.1'), array('10.0.0.2', '127.0.0.1')),
1164+
);
1165+
}
1166+
11451167
/**
11461168
* @dataProvider getXForwardedForData
11471169
*/

0 commit comments

Comments
 (0)