Skip to content

Commit 2183634

Browse files
Merge branch '2.8' into 3.0
* 2.8: [FrameworkBundle] Fix fixtures [HttpKernel] Inline ValidateRequestListener logic into HttpKernel fixed HttpKernel dependencies after #18688 Conflicts: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.txt src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.txt src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.txt src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/event_dispatcher_1_events.txt src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.txt src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.txt src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameter.txt src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.txt src/Symfony/Bundle/FrameworkBundle/composer.json src/Symfony/Component/HttpKernel/composer.json
2 parents 212037f + eaae717 commit 2183634

File tree

5 files changed

+37
-124
lines changed

5 files changed

+37
-124
lines changed

EventListener/ValidateRequestListener.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

HttpKernel.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpKernel;
1313

1414
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
15+
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1516
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1617
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
1718
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
@@ -21,6 +22,7 @@
2122
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
2223
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
2324
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
25+
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
2426
use Symfony\Component\HttpFoundation\Request;
2527
use Symfony\Component\HttpFoundation\RequestStack;
2628
use Symfony\Component\HttpFoundation\Response;
@@ -113,6 +115,13 @@ public function terminateWithException(\Exception $exception)
113115
*/
114116
private function handleRaw(Request $request, $type = self::MASTER_REQUEST)
115117
{
118+
if (self::MASTER_REQUEST === $type && $request::getTrustedProxies()) {
119+
try {
120+
$request->getClientIps();
121+
} catch (ConflictingHeadersException $e) {
122+
throw new BadRequestHttpException('The request headers contain conflicting information regarding the origin of this request.', $e);
123+
}
124+
}
116125
$this->requestStack->push($request);
117126

118127
// request

Tests/EventListener/ValidateRequestListenerTest.php

Lines changed: 0 additions & 67 deletions
This file was deleted.

Tests/HttpKernelTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,33 @@ public function testVerifyRequestStackPushPopDuringHandle()
260260
$kernel->handle($request, HttpKernelInterface::MASTER_REQUEST);
261261
}
262262

263+
/**
264+
* @expectedException Symfony\Component\HttpKernel\Exception\BadRequestHttpException
265+
*/
266+
public function testInconsistentClientIpsOnMasterRequests()
267+
{
268+
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver());
269+
$request = new Request();
270+
$request->setTrustedProxies(array('1.1.1.1'));
271+
$request->server->set('REMOTE_ADDR', '1.1.1.1');
272+
$request->headers->set('FORWARDED', '2.2.2.2');
273+
$request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
274+
275+
$kernel->handle($request, $kernel::MASTER_REQUEST, false);
276+
}
277+
278+
public function testInconsistentClientIpsOnSubRequests()
279+
{
280+
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver());
281+
$request = new Request();
282+
$request->setTrustedProxies(array('1.1.1.1'));
283+
$request->server->set('REMOTE_ADDR', '1.1.1.1');
284+
$request->headers->set('FORWARDED', '2.2.2.2');
285+
$request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
286+
287+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $kernel->handle($request, $kernel::SUB_REQUEST, false));
288+
}
289+
263290
protected function getResolver($controller = null)
264291
{
265292
if (null === $controller) {

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=5.5.9",
2020
"symfony/event-dispatcher": "~2.8|~3.0",
21-
"symfony/http-foundation": "~2.8|~3.0",
21+
"symfony/http-foundation": "~2.8.8|~3.0.8|~3.1.2|~3.2",
2222
"symfony/debug": "~2.8|~3.0",
2323
"psr/log": "~1.0"
2424
},

0 commit comments

Comments
 (0)