Skip to content

[Security] Skip clearing CSRF Token on stateless logout #50312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2023

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented May 13, 2023

Q A
Branch? 6.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #50310
License MIT
Doc PR -

Not targeting 5.4 LTS as the bug is only breaking on 6.3 although it does exist on prior versions.

@@ -31,6 +32,10 @@ public function __construct(ClearableTokenStorageInterface $csrfTokenStorage)

public function onLogout(LogoutEvent $event): void
{
if ($this->csrfTokenStorage instanceof SessionTokenStorage && !$event->getRequest()->hasPreviousSession()) {
Copy link
Member

Choose a reason for hiding this comment

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

What about fixing it in SessionTokenStorage instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Using SessionTokenStorage without a session has been deprecated in 5.x:

public function clear()
{
$session = $this->getSession();
foreach (array_keys($session->all()) as $key) {
if (str_starts_with($key, $this->namespace.'/')) {
$session->remove($key);
}
}
}
/**
* @throws SessionNotFoundException
*/
private function getSession(): SessionInterface

Ideally this listener shouldn't be registered for stateless firewalls, problem is that it's not a per-firewall listener but a global one. We should probably change that in another (feature) PR.

@nicolas-grekas
Copy link
Member

Any way to test this?

@nicolas-grekas
Copy link
Member

Thank you @chalasr.

@nicolas-grekas nicolas-grekas merged commit 684fdd2 into symfony:6.2 May 19, 2023
@chalasr
Copy link
Member Author

chalasr commented May 19, 2023

Any way to test this?

Sure, at least something preventing regressions. I'll do!

@chalasr chalasr deleted the skip-csrfclear-stateless branch May 19, 2023 16:00
chalasr added a commit that referenced this pull request May 19, 2023
…tateless logout (chalasr)

This PR was merged into the 6.2 branch.

Discussion
----------

[Security] Test `CsrfTokenClearingLogoutListener` with stateless logout

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | #50312 (comment)
| License       | MIT
| Doc PR        | -

Commits
-------

099ba75 [Security] Test `CsrfTokenClearingLogoutListener` with stateless logout
This was referenced May 22, 2023
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.

4 participants