Skip to content

fix: Send users to their group homepage after MFA - #7

Merged
hellopablo merged 1 commit into
developfrom
feature/return-to-group-homepage
Sep 9, 2026
Merged

hellopablo merged 1 commit into
developfrom
feature/return-to-group-homepage

Conversation

@hellopablo

@hellopablo hellopablo commented Sep 9, 2026

Copy link
Copy Markdown
Member

Problem

generateToken() falls back to $oInput::server('URI_STRING') when no explicit return_to is supplied:

static::TOKEN_DATA_KEY_RETURN_TO => $oInput::get('return_to') ?: $oInput::server('URI_STRING'),

Input::server() reads $_SERVER, and URI_STRING is never set there by the framework or by any consuming app — the idiom is the uri_string() helper, which the Uri service even advertises as @method uri_string().

So the fallback always evaluates empty and false is stored. On success redirect(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 /dashboard and staff to /admin.

Why not just use uri_string()

It would be wrong here. generateToken() runs after the logout inside authenticate(), 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-auth does itself:

// auth/controllers/Login.php:251
$sRedirectUrl = $this->data['return_to'] ? $this->data['return_to'] : $oUser->group_homepage;

That line never runs in the MFA case, because this module's LogIn listener redirects during the USER_LOG_IN event. The legacy MFA implementation in module-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 catch false, 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:

MFA form: HTTP 200
verify:   HTTP 302
Location: https://localhost/admin

Log now reads User verified successfully, redirecting to "/admin" rather than "".

Made with Cursor

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>
@hellopablo
hellopablo merged commit eb2e769 into develop Sep 9, 2026
4 checks passed
@hellopablo
hellopablo deleted the feature/return-to-group-homepage branch September 9, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant