Skip to content

Commit 29af3be

Browse files
Merge branch '3.4' into 4.4
* 3.4: Handle fetch mode deprecation of DBAL 2.11. Fixed handling of CSRF logout error
2 parents a007bfb + 40f7beb commit 29af3be

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Firewall/ExceptionListener.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function onKernelException(GetResponseForExceptionEvent $event)
111111
}
112112

113113
if ($exception instanceof LogoutException) {
114-
$this->handleLogoutException($exception);
114+
$this->handleLogoutException($event, $exception);
115115

116116
return;
117117
}
@@ -181,10 +181,12 @@ private function handleAccessDeniedException(GetResponseForExceptionEvent $event
181181
}
182182
}
183183

184-
private function handleLogoutException(LogoutException $exception): void
184+
private function handleLogoutException(GetResponseForExceptionEvent $event, LogoutException $exception): void
185185
{
186+
$event->setException(new AccessDeniedHttpException($exception->getMessage(), $exception));
187+
186188
if (null !== $this->logger) {
187-
$this->logger->info('A LogoutException was thrown.', ['exception' => $exception]);
189+
$this->logger->info('A LogoutException was thrown; wrapping with AccessDeniedHttpException', ['exception' => $exception]);
188190
}
189191
}
190192

Tests/Firewall/ExceptionListenerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
2222
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
2323
use Symfony\Component\Security\Core\Exception\AuthenticationException;
24+
use Symfony\Component\Security\Core\Exception\LogoutException;
2425
use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
2526
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
2627
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
@@ -157,6 +158,17 @@ public function testAccessDeniedExceptionNotFullFledged(\Exception $exception, \
157158
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getThrowable()->getPrevious());
158159
}
159160

161+
public function testLogoutException()
162+
{
163+
$event = $this->createEvent(new LogoutException('Invalid CSRF.'));
164+
165+
$listener = $this->createExceptionListener();
166+
$listener->onKernelException($event);
167+
168+
$this->assertEquals('Invalid CSRF.', $event->getException()->getMessage());
169+
$this->assertEquals(403, $event->getException()->getStatusCode());
170+
}
171+
160172
public function getAccessDeniedExceptionProvider()
161173
{
162174
return [

0 commit comments

Comments
 (0)