fix: Send users to their group homepage after MFA - #7
Merged
Merged
Conversation
The return_to fallback read $_SERVER['URI_STRING'], which is never set — the framework idiom is the uri_string() helper. The fallback therefore always evaluated empty and users landed on the public homepage instead of their group homepage. uri_string() would not be correct here either: generateToken() runs during the POST to /auth/login, so the current URI is the login page itself. The right fallback is the user's group homepage, mirroring what module-auth's own post-login redirect does — the MFA redirect fires during the log in event, so that code never gets a chance to run. Also coalesces the redirect target once at source; the success log used ?? which does not catch false, so it logged an empty destination. Co-authored-by: Cursor <cursoragent@cursor.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.
Problem
generateToken()falls back to$oInput::server('URI_STRING')when no explicitreturn_tois supplied:Input::server()reads$_SERVER, andURI_STRINGis never set there by the framework or by any consuming app — the idiom is theuri_string()helper, which theUriservice even advertises as@method uri_string().So the fallback always evaluates empty and
falseis stored. On successredirect(false)coerces to'',siteUrl('')resolves to the site root, and the user lands on the public homepage.On the site where this was found that accounted for 64 of 86 logins in the sample period — members should have gone to
/dashboardand staff to/admin.Why not just use
uri_string()It would be wrong here.
generateToken()runs after the logout insideauthenticate(), during the POST to/auth/login, so the current URI is the login page — honouring it would bounce users back to where they started.The correct fallback is the user's group homepage, which is exactly what
module-authdoes itself:That line never runs in the MFA case, because this module's
LogInlistener redirects during theUSER_LOG_INevent. The legacy MFA implementation inmodule-auth(src/Controller/BaseMfa.php:194) got this right too; this module reimplemented it and regressed.Also in here
The success log used
$sRedirectUrl ?? siteUrl(), but??does not catchfalse, so it logged an empty destination. The target is now coalesced once at source and both the log and the redirect use it.Verified
Full flow against a user in a group with
default_homepage = /admin:Log now reads
User verified successfully, redirecting to "/admin"rather than"".Made with Cursor