Repository navigation
#93 Protect the login form and the logout against CSRF - #94
Draft
njoubert-cleverage wants to merge 2 commits into
Draft
njoubert-cleverage wants to merge 2 commits into
njoubert-cleverage wants to merge 2 commits into
Conversation
The prepended form_login configuration enables enable_csrf (token id `authenticate`, parameter `_csrf_token`) and LoginController passes csrf_token_intention, so that the EasyAdmin login template renders the token field. symfony/security-csrf is declared (it was only a transitive dependency). BC break for overridden login templates, see UPGRADE.md v4.0. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2 of 3 tasks
njoubert-cleverage
marked this pull request as draft
October 8, 2026 09:00
The prepended logout configuration enables enable_csrf (token id `logout`, parameter `_csrf_token`): the logout link of the EasyAdmin menu (LogoutUrlGenerator) carries the token, /process/logout without a valid token is refused (403). UPGRADE.md v4.0 completed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #93.
Milestone v4.0 (BC break, see below).
CleverAgeUiProcessExtension::prepend():enable_csrf: trueon theform_loginof themainfirewall (token idauthenticate, parameter_csrf_token: theform_logindefaults, also used by the EasyAdmin login template)CleverAgeUiProcessExtension::prepend():enable_csrf: trueon thelogoutof themainfirewall (token idlogout, parameter_csrf_token): the logout link of the EasyAdmin user menu (LogoutUrlGenerator) carries the token,/process/logoutwithout a valid token is refused (403)LoginController: passescsrf_token_intention: authenticate, so the EasyAdmin login template renders the_csrf_tokenhidden fieldcomposer.json:symfony/security-csrfdeclared (it was only installed as a transitive dependency)03-users_and_security.md(prepended configuration, CSRF requirements,logout_path()) andUPGRADE.mdv4.0 (overridden login template, own logout links, opt-outs); CHANGELOG entry underBC breakTests:
SecurityTest::testLoginWithAnInvalidCsrfToken: the login page has the_csrf_tokenfield; valid credentials with an invalid token are rejected (Invalid CSRF token.), the user stays logged out.testLoginstill logs in with the token of the pageSecurityTest::testLogout: logout with the link of the user menu (with the token);testLogoutWithoutCsrfToken:/process/logoutwithout token gives a 403, the user stays logged inCleverAgeUiProcessExtensionTest::testPrepend:enable_csrfin the prependedform_loginandlogoutChecked:
composer validate, PHPStan, PHP-CS-Fixer, Rector OKInvalid CSRF token., login with the token of the page redirects to the UI;/process/logoutwithout token: 403, still logged in; logout link of the menu: logged out, redirected to the loginRequirements
Breaking changes
Applications that override the login template without the
_csrf_tokenfield, or that submit the login form without it, must add it, or setform_login.enable_csrf: falseon theirmainfirewall. Links topath('process_logout')in application templates must uselogout_path()(or setlogout.enable_csrf: false). SeeUPGRADE.md. The Symfony CSRF protection must be enabled (framework.csrf_protection, enabled by default when the session is).🤖 Generated with Claude Code