Skip to content
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
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function authenticate(RequestEvent $event): void
$request = $event->getRequest();

if (null !== $this->csrfTokenManager) {
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter'], $request->request->all());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$request->request should be used only for POST requests, not for GET requests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we need to revert the whole PR as is (see #62086) and work on fixing the root issue instead (a URL with an invalid CSRF token being generated).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$request->request->all() is going to be empty so that we'll properly fallback to the query-string on GET requests.


if (!\is_string($csrfToken) || false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['csrf_token_id'], $csrfToken))) {
throw new LogoutException('Invalid CSRF token.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\LogoutException;
use Symfony\Component\Security\Csrf\CsrfToken;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Security\Http\Event\LogoutEvent;
use Symfony\Component\Security\Http\Firewall\LogoutListener;
Expand Down Expand Up @@ -88,6 +89,49 @@ public function testHandleMatchedPathWithCsrfValidation()
$this->assertSame($response, $event->getResponse());
}

public function testHandleMatchedPathWithCsrfInQueryParamAndBody()
{
$tokenManager = $this->getTokenManager();
$dispatcher = $this->getEventDispatcher();

[$listener, $tokenStorage, $httpUtils, $options] = $this->getListener($dispatcher, $tokenManager);

$request = new Request();
$request->query->set('_csrf_token', 'token');
$request->request->set('_csrf_token', 'token2');

$httpUtils->expects($this->once())
->method('checkRequestPath')
->with($request, $options['logout_path'])
->willReturn(true);

$tokenManager->expects($this->once())
->method('isTokenValid')
->with($this->callback(function ($token) {
return $token instanceof CsrfToken && 'token2' === $token->getValue();
}))
->willReturn(true);

$response = new Response();
$dispatcher->addListener(LogoutEvent::class, function (LogoutEvent $event) use ($response) {
$event->setResponse($response);
});

$tokenStorage->expects($this->once())
->method('getToken')
->willReturn($token = $this->getToken());

$tokenStorage->expects($this->once())
->method('setToken')
->with(null);

$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST);

$listener($event);

$this->assertSame($response, $event->getResponse());
}

public function testHandleMatchedPathWithoutCsrfValidation()
{
$dispatcher = $this->getEventDispatcher();
Expand Down