fix incomplete MFA logins having the ability to change state

when a user is part way through an MFA login (username/password auth done, but not the MFA bit),
authentication_get_username() will return their current username. This function is used in various other places
and historically it was a suitable check to determine if someone was also authenticated.

Commit updates authentication_get_username() to include a call to authentication_mfa_incomplete() by default, the only exclusion being on the login-mfa.php pages.

Thanks to Wenhao Wu (Southeast University) for the security report "MFA-incomplete (password-only) mailbox session can rewrite its own alias forwarding via /edit.php (CWE-308)"
This commit is contained in:
David Goodwin authored and Christian Boltz committed 2026-09-29 12:05:32 +00:00
1 parent 02305b0dd5
commit 77ccefdbf2
3 files changed
+21 -11

No files matched your search

+14 -4
View File
@@ -35,12 +35,12 @@ function authentication_mfa_incomplete(): bool
}
/**
* check_session
* Action: Check if a session already exists, if not redirect to login.php
* Call: check_session ()
* Action: Check if a session already exists, if not redirect to login.php. Returns current user's login.
*
* @param bool $requireMfaComplete - false only for login-mfa.php
* @return string username (e.g. foo@example.com) or CLI or SETUP.PHP
*/
function authentication_get_username()
function authentication_get_username(bool $requireMfaComplete = true)
{
if (defined('POSTFIXADMIN_CLI')) {
return 'CLI';
@@ -54,6 +54,16 @@ function authentication_get_username()
header("Location: login.php");
exit(0);
}
/**
* when an mfa user logs in (username+password) but haven't yet done the MFA code, $_SESSION['sessid']['username'] will be populated
* but the user hasn't finished authentication, so we should not treat them as having logged in.
*/
if ($requireMfaComplete && authentication_mfa_incomplete()) {
header("Location: login-mfa.php");
exit(0);
}
return $_SESSION['sessid']['username'];
}
+4 -4
View File
@@ -66,18 +66,18 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
$fTotp = safepost('fTOTP_code');
$h = new AdminHandler();
if (authentication_mfa_incomplete() && $totppf->checkUserTOTP(authentication_get_username(), $fTotp)) {
init_session(authentication_get_username(), true, true);
if (authentication_mfa_incomplete() && $totppf->checkUserTOTP(authentication_get_username(false), $fTotp)) {
init_session(authentication_get_username(false), true, true);
// get superadmin status and store in session
$h->init(authentication_get_username());
$h->init(authentication_get_username(false));
if ($h->result()['superadmin'] == 1) {
$_SESSION['sessid']['roles'][] = 'global-admin';
}
header("Location: main.php");
exit(0);
} else {
error_log("PostfixAdmin admin second factor login failed (username: " . authentication_get_username() . ", ip_address: {$_SERVER['REMOTE_ADDR']})");
error_log("PostfixAdmin admin second factor login failed (username: " . authentication_get_username(false) . ", ip_address: {$_SERVER['REMOTE_ADDR']})");
$error = $PALANG['pTotp_failed'];
flash_error($PALANG['pTotp_failed']);
}
+3 -3
View File
@@ -60,12 +60,12 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
$totppf = new TotpPf('mailbox', new Login('mailbox'));
$fTotp = safepost('fTOTP_code');
if (authentication_mfa_incomplete() && $totppf->checkUserTOTP(authentication_get_username(), $fTotp)) {
init_session(authentication_get_username(), false, true);
if (authentication_mfa_incomplete() && $totppf->checkUserTOTP(authentication_get_username(false), $fTotp)) {
init_session(authentication_get_username(false), false, true);
header("Location: main.php");
exit(0);
} else { # $h->login failed
error_log("PostfixAdmin admin second factor login failed (username: " . authentication_get_username() . ", ip_address: {$_SERVER['REMOTE_ADDR']})");
error_log("PostfixAdmin admin second factor login failed (username: " . authentication_get_username(false) . ", ip_address: {$_SERVER['REMOTE_ADDR']})");
flash_error($PALANG['pTotp_failed']);
}
}