Skip to content

Commit

Permalink
bug #22285 [HttpKernel] Fix forward compat with Request::setTrustedPr…
Browse files Browse the repository at this point in the history
…oxies() (nicolas-grekas)

This PR was merged into the 3.2 branch.

Discussion
----------

[HttpKernel] Fix forward compat with Request::setTrustedProxies()

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Should make travis green again.

Commits
-------

6ecec35 [HttpKernel] Fix forward compat with Request::setTrustedProxies()
  • Loading branch information
nicolas-grekas committed Apr 5, 2017
2 parents 761d452 + 6ecec35 commit db8231e
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
Expand Up @@ -36,7 +36,7 @@ public function testUsesRequestServerData()

public function testUseRequestClientIp()
{
Request::setTrustedProxies(array('192.168.0.1'));
Request::setTrustedProxies(array('192.168.0.1'), -1);
list($event, $server) = $this->createRequestEvent(array('X_FORWARDED_FOR' => '192.168.0.2'));

$processor = new WebProcessor();
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php
Expand Up @@ -464,7 +464,7 @@ protected function forward(Request $request, $catch = false, Response $entry = n
// make sure HttpCache is a trusted proxy
if (!in_array('127.0.0.1', $trustedProxies = Request::getTrustedProxies())) {
$trustedProxies[] = '127.0.0.1';
Request::setTrustedProxies($trustedProxies);
Request::setTrustedProxies($trustedProxies, method_exists('Request', 'getTrustedHeaderSet') ? Request::getTrustedHeaderSet() : -1);
}

// always a "master" request (as the real master request can be in cache)
Expand Down
Expand Up @@ -30,7 +30,7 @@ public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps()
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();

$request = new Request();
$request->setTrustedProxies(array('1.1.1.1'));
$request->setTrustedProxies(array('1.1.1.1'), -1);
$request->server->set('REMOTE_ADDR', '1.1.1.1');
$request->headers->set('FORWARDED', 'for=2.2.2.2');
$request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
Expand Down
Expand Up @@ -1218,7 +1218,7 @@ public function testClientIpIsAlwaysLocalhostForForwardedRequests()
*/
public function testHttpCacheIsSetAsATrustedProxy(array $existing, array $expected)
{
Request::setTrustedProxies($existing);
Request::setTrustedProxies($existing, -1);

$this->setNextResponse();
$this->request('GET', '/', array('REMOTE_ADDR' => '10.0.0.1'));
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php
Expand Up @@ -309,7 +309,7 @@ public function testVerifyRequestStackPushPopDuringHandle()
public function testInconsistentClientIpsOnMasterRequests()
{
$request = new Request();
$request->setTrustedProxies(array('1.1.1.1'));
$request->setTrustedProxies(array('1.1.1.1'), -1);
$request->server->set('REMOTE_ADDR', '1.1.1.1');
$request->headers->set('FORWARDED', 'for=2.2.2.2');
$request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
Expand Down

0 comments on commit db8231e

Please sign in to comment.