Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bug #25750 [HttpKernel] Turn bad hosts into 400 instead of 500 (nicol…
…as-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[HttpKernel] Turn bad hosts into 400 instead of 500

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

Commits
-------

3e47c71 [HttpKernel] Turn bad hosts into 400 instead of 500
  • Loading branch information
fabpot committed Jan 10, 2018
2 parents fad59b3 + 3e47c71 commit f35a7b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\RequestStack;
Expand Down Expand Up @@ -96,7 +97,11 @@ public function setRequest(Request $request = null)
private function setCurrentRequest(Request $request = null)
{
if (null !== $request && $this->request !== $request) {
$this->context->fromRequest($request);
try {
$this->context->fromRequest($request);
} catch (\UnexpectedValueException $e) {
throw new BadRequestHttpException($e->getMessage(), $e, $e->getCode());
}
}

$this->request = $request;
Expand Down
Expand Up @@ -155,4 +155,19 @@ public function getLoggingParameterData()
array(array(), 'Matched route "n/a".'),
);
}

/**
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
*/
public function testSubRequestWithBadHost()
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$request = Request::create('http://bad host %22/');
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);

$requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();

$listener = new RouterListener($requestMatcher, new RequestContext(), null, $this->requestStack);
$listener->onKernelRequest($event);
}
}

0 comments on commit f35a7b5

Please sign in to comment.