Skip to content

Commit 30f4146

Browse files
Merge branch '7.4' into 8.0
* 7.4: Fix generating logout link with stateless csrf [AssetMapper] Fix tests [Notifier] Add support for `confirm` option in Slack buttons API [DebugBundle] Wire `DumpDataCollector`'s `webMode` argument filter should be empty when filtering on all domains [Routing] Initialize `router.request_context`'s `_locale` parameter to `%kernel.default_locale%`
2 parents 3f8fcde + 26e1795 commit 30f4146

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

Firewall/LogoutListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function authenticate(RequestEvent $event): void
6969
$request = $event->getRequest();
7070

7171
if (null !== $this->csrfTokenManager) {
72-
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
72+
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter'], $request->request->all());
7373

7474
if (!\is_string($csrfToken) || false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['csrf_token_id'], $csrfToken))) {
7575
throw new LogoutException('Invalid CSRF token.');

Tests/Firewall/LogoutListenerTest.php

Lines changed: 44 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\Authentication\Token\TokenInterface;
2323
use Symfony\Component\Security\Core\Exception\LogoutException;
24+
use Symfony\Component\Security\Csrf\CsrfToken;
2425
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
2526
use Symfony\Component\Security\Http\Event\LogoutEvent;
2627
use Symfony\Component\Security\Http\Firewall\LogoutListener;
@@ -82,6 +83,49 @@ public function testHandleMatchedPathWithCsrfValidation()
8283
$this->assertSame($response, $event->getResponse());
8384
}
8485

86+
public function testHandleMatchedPathWithCsrfInQueryParamAndBody()
87+
{
88+
$tokenManager = $this->getTokenManager();
89+
$dispatcher = $this->getEventDispatcher();
90+
91+
[$listener, $tokenStorage, $httpUtils, $options] = $this->getListener($dispatcher, $tokenManager);
92+
93+
$request = new Request();
94+
$request->query->set('_csrf_token', 'token');
95+
$request->request->set('_csrf_token', 'token2');
96+
97+
$httpUtils->expects($this->once())
98+
->method('checkRequestPath')
99+
->with($request, $options['logout_path'])
100+
->willReturn(true);
101+
102+
$tokenManager->expects($this->once())
103+
->method('isTokenValid')
104+
->with($this->callback(function ($token) {
105+
return $token instanceof CsrfToken && 'token2' === $token->getValue();
106+
}))
107+
->willReturn(true);
108+
109+
$response = new Response();
110+
$dispatcher->addListener(LogoutEvent::class, function (LogoutEvent $event) use ($response) {
111+
$event->setResponse($response);
112+
});
113+
114+
$tokenStorage->expects($this->once())
115+
->method('getToken')
116+
->willReturn($token = $this->getToken());
117+
118+
$tokenStorage->expects($this->once())
119+
->method('setToken')
120+
->with(null);
121+
122+
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST);
123+
124+
$listener($event);
125+
126+
$this->assertSame($response, $event->getResponse());
127+
}
128+
85129
public function testHandleMatchedPathWithoutCsrfValidation()
86130
{
87131
$dispatcher = $this->getEventDispatcher();

0 commit comments

Comments
 (0)