Repository navigation
Fix login loop for teachers with two-factor logging in on My Courses - #8475
Open
benitoalba wants to merge 1 commit into
Open
benitoalba wants to merge 1 commit into
benitoalba wants to merge 1 commit into
Conversation
teacher_login_redirect() redirected and exited on wp_login at priority 99, so later wp_login handlers never ran. Two Factor shows its code screen from a wp_login handler at PHP_INT_MAX, so teachers with 2FA who logged in on the My Courses page were sent to wp-admin without a session and back to wp-login.php in a loop. Request the dashboard redirect instead, when the login request doesn't ask for one. Sensei's login handler and Two Factor's code form both read redirect_to, so the teacher still lands on the dashboard once the login finishes. Fixes Automattic#8470.
This branch has not been deployed
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.
Resolves #8470
Proposed Changes
teacher_login_redirect()no longer redirects and exits onwp_login. When a teacher (or admin) logs in on the My Courses page and the request doesn't already ask for a redirect, it setsredirect_toto the dashboard instead.wp_loginhandlers run. Two Factor shows its code screen from one atPHP_INT_MAX, so teachers with 2FA now get the code screen instead of a login loop.redirect_toafterwp_signon(), and Two Factor carriesredirect_tothrough its code form and redirects there once the code is accepted.I set
redirect_tohere rather than moving the redirect to thelogin_redirectfilter, as the triage suggested, because the My Courses form posts to the My Courses page, not to wp-login.php, sologin_redirectnever runs for it. Two Factor 0.17.0 also redirects to whateverredirect_toit was given after the code, and Sensei's form doesn't send one, so with only a filter the teacher would end up on an empty redirect after entering the code.A
redirect_tothe request already asks for is kept, the same as before. Students, and teachers who log in elsewhere, are unaffected.Testing Instructions
trunk: you're sent to wp-admin and straight back towp-login.php?...&reauth=1, with no code screen.I ran steps 3 to 7 on wp-env with Two Factor 0.17.0 (Dummy provider) in Chromium. New PHPUnit tests in
Sensei_Class_Teacher_Testcover the dashboard redirect, a requested redirect being kept, students and other pages, and laterwp_loginhandlers still running. The class passes (31 tests), and the three teacher-on-My-Courses tests fail ontrunk.scripts/linter-cireports no new issues.