diff --git a/data/web/inc/functions.admin.inc.php b/data/web/inc/functions.admin.inc.php index 69f1b7e56..47be36cc7 100644 --- a/data/web/inc/functions.admin.inc.php +++ b/data/web/inc/functions.admin.inc.php @@ -74,6 +74,15 @@ function admin($_action, $_data = null) { $usernames = $_data['username']; } foreach ($usernames as $username) { + // A pending password update only allows changing the own password + if (!empty($_SESSION['pending_pw_update']) && $username != $_SESSION['mailcow_cc_username']) { + $_SESSION['return'][] = array( + 'type' => 'danger', + 'log' => array(__FUNCTION__, $_action, $_data_log), + 'msg' => 'access_denied' + ); + continue; + } $is_now = admin('details', $username); if (!empty($is_now)) { $active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active']; diff --git a/data/web/json_api.php b/data/web/json_api.php index 104355b74..9e147a18f 100644 --- a/data/web/json_api.php +++ b/data/web/json_api.php @@ -105,6 +105,24 @@ if (isset($_GET['query'])) { 'msg' => 'Cannot find attributes in post data' )); + // A login with pending 2FA setup or password update may only use the calls of these steps + if (!empty($_SESSION['pending_tfa_setup']) || !empty($_SESSION['pending_pw_update'])) { + if (!empty($_SESSION['pending_tfa_setup'])) { + $pending_allowed = array('get/passwordpolicy', 'get/webauthn-tfa-registration', 'add/webauthn-tfa-registration'); + } + else { + $pending_allowed = array('get/passwordpolicy', 'edit/self', 'edit/admin'); + } + if (!in_array($action . '/' . $category, $pending_allowed)) { + http_response_code(403); + echo json_encode(array( + 'type' => 'error', + 'msg' => 'API access denied until the pending account setup is finished' + )); + exit(); + } + } + switch ($action) { case "add": if ($_SESSION['mailcow_cc_api_access'] == 'ro' || isset($_SESSION['pending_mailcow_cc_username']) || !isset($_SESSION["mailcow_cc_username"])) {