Skip to content

Commit 53a3d19

Browse files
committed
Merge branch '2.4' into 2.5
* 2.4: [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
2 parents 48eb520 + 5dc93f0 commit 53a3d19

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
@@ -461,6 +461,12 @@ protected function forward(Request $request, $catch = false, Response $entry = n
461461
// is always called from the same process as the backend.
462462
$request->server->set('REMOTE_ADDR', '127.0.0.1');
463463

464+
// make sure HttpCache is a trusted proxy
465+
if (!in_array('127.0.0.1', $trustedProxies = Request::getTrustedProxies())) {
466+
$trustedProxies[] = '127.0.0.1';
467+
Request::setTrustedProxies($trustedProxies);
468+
}
469+
464470
// always a "master" request (as the real master request can be in cache)
465471
$response = $this->kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, $catch);
466472
// FIXME: we probably need to also catch exceptions if raw === true
@@ -601,8 +607,6 @@ protected function store(Request $request, Response $response)
601607
*
602608
* @param Request $request A Request instance
603609
* @param Response $response A Response instance
604-
*
605-
* @return Response A Response instance
606610
*/
607611
private function restoreResponseBody(Request $request, Response $response)
608612
{

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)