Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpFoundation] Warning when request has both Forwarded and X-Forwarded-For #18688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Prev Previous commit
Next Next commit
Renamed listener and CS fixes.
  • Loading branch information
magnusnordlander committed Jun 28, 2016
commit 66f19f12cb450f22d7092ee085587bdd2371abf7
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<tag name="kernel.event_subscriber" />
</service>

<service id="validate_request_client_ip_listener" class="Symfony\Component\HttpKernel\EventListener\ValidateRequestClientIpListener">
<service id="validate_request_listener" class="Symfony\Component\HttpKernel\EventListener\ValidateRequestListener">
<tag name="kernel.event_subscriber" />
</service>
</services>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\KernelEvents;

/**
Expand All @@ -24,7 +23,7 @@
*
* @author Magnus Nordlander <magnus@fervo.se>
*/
class ValidateRequestClientIpListener implements EventSubscriberInterface
class ValidateRequestListener implements EventSubscriberInterface
{
/**
* Performs the validation.
Expand All @@ -33,12 +32,12 @@ class ValidateRequestClientIpListener implements EventSubscriberInterface
*/
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
if ($event->isMasterRequest()) {
try {
// This will throw an exception if the headers are inconsistent.
$event->getRequest()->getClientIps();
} catch (ConflictingHeadersException $e) {
throw new HttpException(400, 'The request headers contain conflicting information regarding the origin of this request.', $e);
throw new BadRequestHttpException('The request headers contain conflicting information regarding the origin of this request.', $e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\EventListener\ValidateRequestClientIpListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;

class ValidateRequestClientIpTest extends \PHPUnit_Framework_TestCase
class ValidateRequestListenerTest extends \PHPUnit_Framework_TestCase
{
public function testListenerThrowsOnInconsistentMasterRequests()
public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
Expand All @@ -37,7 +36,7 @@ public function testListenerThrowsOnInconsistentMasterRequests()
$dispatcher->dispatch(KernelEvents::REQUEST, $event);
}

public function testListenerDoesNothingOnConsistentRequests()
public function testListenerDoesNothingOnValidRequests()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.