Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Routing][Security] When a#[Route] is marked asstateless: true and theSameOriginCsrfTokenManager.php, the check fails #59092

Closed
@Crovitche-1623

Description

@Crovitche-1623

Symfony version(s) affected

7.2.0

Description

When a#[Route] is marked asstateless: true and theSameOriginCsrfTokenManager.php configuration is enabled, the stateless check fails because thehasSession(true)condition passes and the code is executed when it shouldn't be. Therefore, the CSRF strategy is persisted in the session (I have acsrf-token with the value1 instead of no value at all).

To make the stateless check pass, I had to modify the following code:

// line 208 of Symfony\Component\Security\Csrf\SameOriginCsrfTokenManager.phppublicfunctionpersistStrategy(Request$request):void    {if ($request->hasSession(true) &&$request->attributes->has($this->cookieName)) {$request->getSession()->set($this->cookieName,$request->attributes->get($this->cookieName));        }    }

to

publicfunctionpersistStrategy(Request$request):void    {if ($request->hasSession(true) &&$request->getSession()->isStarted() &&$request->attributes->has($this->cookieName)) {$request->getSession()->set($this->cookieName,$request->attributes->get($this->cookieName));        }    }

@nicolas-grekas Maybe you wanted to check if the session was started instead of if a Session object exists ?

How to reproduce

Make a route marked as stateless. For instance:

#[Route(    path: ['fr' =>'/se_connecter','en' =>'/login',    ],    name:'login',    stateless:true,)]publicfunctionlogin() {// ...}

And configure the app to use stateless CSRF token (https://symfony.com/blog/new-in-symfony-7-2-stateless-csrf)

Possible Solution

Check if the session is started instead of the session exists to define if a value must be written in the session or not.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp