Skip to content

Commit ca65362

Browse files
Make sure HttpCache is a trusted proxy
1 parent 7b6161c commit ca65362

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php

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

465+
// make sure HttpCache is a trusted proxy
466+
if (!in_array('127.0.0.1', $trustedProxies = Request::getTrustedProxies())) {
467+
$trustedProxies[] = '127.0.0.1';
468+
Request::setTrustedProxies($trustedProxies);
469+
}
470+
465471
// always a "master" request (as the real master request can be in cache)
466472
$response = $this->kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, $catch);
467473
// FIXME: we probably need to also catch exceptions if raw === true

src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php

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

1158+
/**
1159+
* @dataProvider getTrustedProxyData
1160+
*/
1161+
public function testHttpCacheIsSetAsATrustedProxy(array $existing, array $expected)
1162+
{
1163+
Request::setTrustedProxies($existing);
1164+
1165+
$this->setNextResponse();
1166+
$this->request('GET', '/', array('REMOTE_ADDR' => '10.0.0.1'));
1167+
1168+
$this->assertEquals($expected, Request::getTrustedProxies());
1169+
}
1170+
1171+
public function getTrustedProxyData()
1172+
{
1173+
return array(
1174+
array(array(), array('127.0.0.1')),
1175+
array(array('10.0.0.2'), array('10.0.0.2', '127.0.0.1')),
1176+
array(array('10.0.0.2', '127.0.0.1'), array('10.0.0.2', '127.0.0.1')),
1177+
);
1178+
}
1179+
11581180
/**
11591181
* @dataProvider getXForwardedForData
11601182
*/

0 commit comments

Comments
 (0)