Skip to content

Commit

Permalink
Fixed handling of CSRF logout error
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed May 26, 2020
1 parent 4f40da5 commit 69be9fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Expand Up @@ -102,7 +102,7 @@ public function onKernelException(GetResponseForExceptionEvent $event)
}

if ($exception instanceof LogoutException) {
$this->handleLogoutException($exception);
$this->handleLogoutException($event, $exception);

return;
}
Expand Down Expand Up @@ -172,10 +172,12 @@ private function handleAccessDeniedException(GetResponseForExceptionEvent $event
}
}

private function handleLogoutException(LogoutException $exception)
private function handleLogoutException(GetResponseForExceptionEvent $event, LogoutException $exception)
{
$event->setException(new AccessDeniedHttpException($exception->getMessage(), $exception));

if (null !== $this->logger) {
$this->logger->info('A LogoutException was thrown.', ['exception' => $exception]);
$this->logger->info('A LogoutException was thrown; wrapping with AccessDeniedHttpException', ['exception' => $exception]);
}
}

Expand Down
Expand Up @@ -21,6 +21,7 @@
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\LogoutException;
use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
Expand Down Expand Up @@ -160,6 +161,17 @@ public function testAccessDeniedExceptionNotFullFledged(\Exception $exception, \
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
}

public function testLogoutException()
{
$event = $this->createEvent(new LogoutException('Invalid CSRF.'));

$listener = $this->createExceptionListener();
$listener->onKernelException($event);

$this->assertEquals('Forbidden', $event->getResponse()->getContent());
$this->assertEquals(403, $event->getResponse()->getStatusCode());
}

public function getAccessDeniedExceptionProvider()
{
return [
Expand Down

0 comments on commit 69be9fe

Please sign in to comment.