8000 [Security] Fixed handling of CSRF logout error by wouterj · Pull Request #36974 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Security] Fixed handling of CSRF logout error #36974

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading 8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed han 8000 dling of CSRF logout error
  • Loading branch information
wouterj committed May 26, 2020
commit 50348f2eb70501ec706b6effb9afe073a60c1e6d
Original file line number Diff line number Diff line change
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 8000 $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
Original file line number Diff line number Diff line change
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, \
$ 65E5 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('Invalid CSRF.', $event->getException()->getMessage());
$this->assertEquals(403, $event->getException()->getStatusCode());
}

public function getAccessDeniedExceptionProvider()
{
return [
Expand Down
0