Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

pierredup
Copy link
Contributor

@pierredup pierredup commented Oct 10, 2025

Q A
Branch? 7.3
Bug fix? yes
New feature? no
Deprecations? no
Issues N/A
License MIT

When using the logout_path (or logout_url) twig function with stateless csrf, the generator creates a link with an invalid CSRF token parameter (/logout?_csrf_token=csrf-token), which then causes an error during logout (Invalid CSRF token), since the LogoutListener reads the token from the query parameter first.

Reproducer:

framework:
    csrf_protection:
        stateless_token_ids: ['logout']
<form method="post" action="{{ logout_path() }}">
    <input type="hidden" data-controller="csrf-protection" name="_csrf_token" value="{{ csrf_token('logout') }}"/>
    <button type="submit">Logout</button>
</form>

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.3" but it seems your PR description refers to branch "7.3 for bug fixes".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@carsonbot carsonbot changed the title Fix generating logout link with stateless csrf Fix generating logout link with stateless csrf Oct 10, 2025
@pierredup pierredup changed the title Fix generating logout link with stateless csrf [Security] Fix generating logout link with stateless csrf Oct 10, 2025
@carsonbot carsonbot changed the title [Security] Fix generating logout link with stateless csrf Fix generating logout link with stateless csrf Oct 12, 2025
@nicolas-grekas
Copy link
Member

Thank you @pierredup.

@nicolas-grekas nicolas-grekas merged commit c1e91c5 into symfony:7.3 Oct 13, 2025
11 checks passed

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.