Repository navigation
fix: pass csrf token when re-rendering the admin login form after failed credentials - #519
Merged
Merged
Conversation
…led credentials The invalid-credentials branch of LoginController::authenticate() rendered the login view without csrfToken, so the templates fell back to an empty hidden _token field and the admin's next login attempt was rejected by CsrfMiddleware with a 419. Pass the session token on that re-render, like the GET form and the 429 lockout branch already do. Adds a feature test that drives the real CsrfMiddleware and CsrfTokenManager over one session: GET form, wrong password, then the correct password using the token from the re-rendered form, which now redirects to the dashboard. Fixes #511 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KyjR4cJTfro54iFZ9CWkv1
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.
Summary
LoginController::authenticate()re-rendered the login form on invalid credentials withoutcsrfToken, so the latte/twig templates fell back to an empty hidden_tokenand the admin's second attempt was rejected byCsrfMiddleware(419) instead of being checked.csrfTokenfromCsrfTokenManagerInterface::get(), matching the GET form and the 429 lockout branch. Those are the only re-renders: the controller has no separate validation-error path.Test plan
packages/admin-panel/tests/Feature/LoginRerenderCsrfTest.phpuses the realCsrfMiddlewareandCsrfTokenManagerover oneFakeSession. It GETs the form, posts a wrong password, reads_tokenfrom the re-rendered form, then posts the correct password with that token and gets a 302 to/admin. Before the fix it fails withCsrfTokenMismatchException.csrfTokenis passed to the view.composer cigreen locallyFixes #511
🤖 Generated with Claude Code
https://claude.ai/code/session_01KyjR4cJTfro54iFZ9CWkv1