fix: MFA login fails with CSRF token validation error due to duplicate form submission#3371
fix: MFA login fails with CSRF token validation error due to duplicate form submission#3371yog27ray wants to merge 1 commit into
Conversation
…e form submission
|
🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review. Tip
Note Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect. Caution Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughLoginForm refactored to eliminate duplicate form submissions during MFA login. The component removes its formRef mechanism and the corresponding manual form.submit() call in the onClick handler, preventing a secondary submission that destroyed the session after Passport's session regeneration. Tests added to validate single submission behavior. ChangesMFA Login Form Submission Fix
🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 7✅ Passed checks (7 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 OpenGrep (1.22.0)OpenGrep fatal error (exit code 2): [00.12][ERROR]: Error: exception Unix_error: No such file or directory stat src/components/LoginForm/LoginForm.react.js Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
New Pull Request Checklist
Issue Description
Closes: #3370
Logging in with MFA (OTP) enabled fails with
CSRF token validation failed. Please refresh the page and try again.(HTTP 403,EBADCSRFTOKEN). The password step works; the failure is on the OTP step. It reproduces on a single instance, in incognito, with no extensions, so it is not the multi-replica / sticky-session case from #3015.Root Cause
LoginForm.react.jssubmits the form twice per click. The button istype="submit"(which natively submits the form as the click's default action) and itsonClickalso callsthis.formRef.current.submit(), a second programmatic submission:On the password step both submissions return 302, so the duplicate is harmless. On the MFA step the first submission authenticates; Passport's
req.logInthen callsreq.session.regenerate()(session-fixation protection), which destroys the session holding the CSRF token (csrf-syncstores it inreq.session). The browser cancels that response and never receives the regenerated cookie, so the second submission lands on the dead session, finds no CSRF token, and fails with 403.Approach
Remove the redundant programmatic
this.formRef.current.submit()and let the nativetype="submit"submit the form exactly once. The synchronousformSubmit()side effect still runs first, and Enter-key submission is preserved. The now-unusedformRef(React.createRef()+ref=) is removed.TODOs before merging
Summary by CodeRabbit
Bug Fixes
Tests