Skip to content

fix: pass csrf token when re-rendering the admin login form after failed credentials - #519

Merged
markshust merged 1 commit into
developfrom
feature/admin-login-rerender-csrf
Oct 6, 2026
Merged

markshust merged 1 commit into
developfrom
feature/admin-login-rerender-csrf

Conversation

@markshust

Copy link
Copy Markdown
Collaborator

Summary

  • LoginController::authenticate() re-rendered the login form on invalid credentials without csrfToken, so the latte/twig templates fell back to an empty hidden _token and the admin's second attempt was rejected by CsrfMiddleware (419) instead of being checked.
  • The invalid-credentials branch now passes csrfToken from CsrfTokenManagerInterface::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

  • New packages/admin-panel/tests/Feature/LoginRerenderCsrfTest.php uses the real CsrfMiddleware and CsrfTokenManager over one FakeSession. It GETs the form, posts a wrong password, reads _token from the re-rendered form, then posts the correct password with that token and gets a 302 to /admin. Before the fix it fails with CsrfTokenMismatchException.
  • The existing unit test for invalid credentials now also asserts that csrfToken is passed to the view.
  • composer ci green locally

Fixes #511

🤖 Generated with Claude Code

https://claude.ai/code/session_01KyjR4cJTfro54iFZ9CWkv1

…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
@github-actions github-actions Bot added the bug Something isn't working label Oct 6, 2026
@markshust
markshust merged commit 5177ed1 into develop Oct 6, 2026
5 checks passed
@markshust
markshust deleted the feature/admin-login-rerender-csrf branch October 6, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Admin failed-login re-render omits csrfToken, so the second login attempt fails CSRF

1 participant