mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 09:09:01 +00:00
Passkeys: agents and client portal contacts can add a passkey with their password and sign in with it instead of their email and password, counting as two-step sign-in; a passkey that supports PRF also opens an agent's credential vault, otherwise credentials stay locked until they type their password once; admins can turn passkeys off in Security settings, and resetting MFA, turning off a contact's two-step sign-in, archiving an agent and the incident password reset remove them; database 4.2.2 adds user_passkeys, users.user_passkey_handle and settings.config_login_passkeys, and lbuchs/WebAuthn 2.2.0 is bundled in libs/webauthn
This commit is contained in:
@@ -99,6 +99,10 @@ if (isset($_GET['portal_user_reset_mfa'])) {
|
||||
$row = portalUserForRequest($_GET['portal_user_reset_mfa']);
|
||||
|
||||
portalMfaReset($row['user_id']);
|
||||
// Their passkeys count as two-step sign-in, and go too (functions/passkey.php)
|
||||
if (passkeysReady()) {
|
||||
passkeysForget($row['user_id']);
|
||||
}
|
||||
logAudit("Contact", "Edit", "$session_name turned off two-step sign-in for " . escapeSql($row['contact_name']) . " in the client portal", $row['client_id'], $row['contact_id']);
|
||||
portalMailAccountChange($row['user_email'], $row['contact_name'], 'mfa_off_by_us');
|
||||
|
||||
@@ -198,6 +202,9 @@ if (isset($_POST['bulk_portal_reset_mfa'])) {
|
||||
continue;
|
||||
}
|
||||
portalMfaReset($user_id);
|
||||
if (passkeysReady()) {
|
||||
passkeysForget($user_id);
|
||||
}
|
||||
logAudit("Contact", "Edit", "$session_name turned off two-step sign-in for " . escapeSql($row['contact_name']) . " in the client portal", $row['client_id'], $row['contact_id']);
|
||||
portalMailAccountChange($row['user_email'], $row['contact_name'], 'mfa_off_by_us');
|
||||
$count++;
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
/*
|
||||
* Admin > Settings > Security (admin/settings_security.php):
|
||||
* edit_security_settings saves the sign-in page's message and login key, how
|
||||
* long a browser is remembered, when admins hear of failed sign-ins, whether
|
||||
* the API takes a key in the address, and shared links. A login key required with none set - which would leave
|
||||
* long a browser is remembered, whether passkeys sign people in, when admins
|
||||
* hear of failed sign-ins, whether the API takes a key in the address, and
|
||||
* shared links. A login key required with none set - which would leave
|
||||
* agents no way in but the database - is refused, as is a key that couldn't
|
||||
* be typed into an address, or a time out of range. Nothing is saved then.
|
||||
* A choice not offered settles to the usual one.
|
||||
@@ -16,8 +17,10 @@ if (isset($_POST['edit_security_settings'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$before = settingsCurrent(['config_login_message', 'config_login_key_required', 'config_login_key_secret', 'config_login_remember_me_expire',
|
||||
'config_login_alert_failures', 'config_api_key_in_address', 'config_share_max_hours', 'config_share_require_protection']);
|
||||
$before = settingsCurrent(array_merge(['config_login_message', 'config_login_key_required', 'config_login_key_secret', 'config_login_remember_me_expire',
|
||||
'config_login_alert_failures', 'config_api_key_in_address', 'config_share_max_hours', 'config_share_require_protection'],
|
||||
// Passkeys, once the database has them (functions/passkey.php)
|
||||
passkeysReady() ? ['config_login_passkeys'] : []));
|
||||
|
||||
// What was sent, and what is saved for anything that wasn't - a switch not sent is off
|
||||
$in = $_POST + array_map(function ($value) { return (string) $value; }, $before);
|
||||
@@ -32,6 +35,9 @@ if (isset($_POST['edit_security_settings'])) {
|
||||
'config_share_max_hours' => intval($in['config_share_max_hours']),
|
||||
'config_share_require_protection' => empty($_POST['config_share_require_protection']) ? 0 : 1,
|
||||
];
|
||||
if (array_key_exists('config_login_passkeys', $before)) {
|
||||
$after['config_login_passkeys'] = empty($_POST['config_login_passkeys']) ? 0 : 1;
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
if ($after['config_login_key_secret'] !== '' && !preg_match('/^\w{3,99}$/', $after['config_login_key_secret'])) {
|
||||
|
||||
@@ -285,10 +285,14 @@ if (isset($_POST['edit_user'])) {
|
||||
$changes[] = 'password changed';
|
||||
userNotifyChange($name, $email, 'an administrator set a new password');
|
||||
}
|
||||
if (!empty($_POST['reset_mfa']) && trim((string) $row['user_token']) !== '') {
|
||||
if (!empty($_POST['reset_mfa']) && (trim((string) $row['user_token']) !== '' || (passkeysReady() && passkeyCount($user_id)))) {
|
||||
userResetMfa($user_id);
|
||||
$passkeys_removed = passkeysReady() ? passkeysForget($user_id) : 0;
|
||||
if ($passkeys_removed) {
|
||||
$changes[] = 'passkeys removed';
|
||||
}
|
||||
$changes[] = 'MFA reset';
|
||||
userNotifyChange($name, $email, 'an administrator turned off multi-factor authentication' . ($force_mfa ? ' - you will set it up again at your next sign in' : ''));
|
||||
userNotifyChange($name, $email, 'an administrator turned off multi-factor authentication' . ($passkeys_removed ? ' and removed your passkeys' : '') . ($force_mfa ? ' - you will set it up again at your next sign in' : ''));
|
||||
}
|
||||
if (strcasecmp($email, $row['user_email']) !== 0) {
|
||||
$changes[] = 'email changed';
|
||||
@@ -388,9 +392,11 @@ if (isset($_GET['reset_user_mfa'])) {
|
||||
$user_id = intval($row['user_id']);
|
||||
|
||||
userResetMfa($user_id);
|
||||
userNotifyChange($row['user_name'], $row['user_email'], 'an administrator turned off multi-factor authentication' . (intval($row['user_config_force_mfa']) ? ' - you will set it up again at your next sign in' : ''));
|
||||
// Their passkeys count as MFA, and go too (functions/passkey.php)
|
||||
$passkeys_removed = passkeysReady() ? passkeysForget($user_id) : 0;
|
||||
userNotifyChange($row['user_name'], $row['user_email'], 'an administrator turned off multi-factor authentication' . ($passkeys_removed ? ' and removed your passkeys' : '') . (intval($row['user_config_force_mfa']) ? ' - you will set it up again at your next sign in' : ''));
|
||||
|
||||
logAudit("User", "Edit", "$session_name reset MFA for user " . escapeSql($row['user_name']), 0, $user_id);
|
||||
logAudit("User", "Edit", "$session_name reset MFA for user " . escapeSql($row['user_name']) . ($passkeys_removed ? " and removed their passkeys" : ''), 0, $user_id);
|
||||
|
||||
flashAlert("MFA reset for <strong>" . $row['user_name'] . "</strong>" . (intval($row['user_config_force_mfa']) ? ' - they set it up again at their next sign in' : ' - they sign in with their password alone until they turn it on'));
|
||||
|
||||
@@ -418,6 +424,9 @@ if (isset($_POST['archive_user'])) {
|
||||
$scrambled = escapeSql(password_hash(randomString(), PASSWORD_DEFAULT));
|
||||
mysqli_query($mysqli, "UPDATE users SET user_name = '$archived_name', user_password = '$scrambled', user_status = 0, user_specific_encryption_ciphertext = '', user_archived_at = NOW() WHERE user_id = $user_id");
|
||||
mysqli_query($mysqli, "DELETE FROM remember_tokens WHERE remember_token_user_id = $user_id");
|
||||
if (passkeysReady()) {
|
||||
passkeysForget($user_id);
|
||||
}
|
||||
|
||||
logAudit("User", "Archive", "$session_name archived user " . escapeSql($row['user_name']), 0, $user_id);
|
||||
|
||||
@@ -653,12 +662,15 @@ if (isset($_POST['ir_reset_user_password'])) {
|
||||
while ($row = mysqli_fetch_assoc($sql_users)) {
|
||||
$new_password = generateReadablePassword(4);
|
||||
userSetPassword($row['user_id'], $new_password);
|
||||
// A remembered browser would skip their MFA code - in an incident, it must not
|
||||
// A remembered browser would skip their MFA code, and a passkey their password - in an incident, neither must
|
||||
mysqli_query($mysqli, "DELETE FROM remember_tokens WHERE remember_token_user_id = " . intval($row['user_id']));
|
||||
if (passkeysReady()) {
|
||||
passkeysForget($row['user_id']);
|
||||
}
|
||||
$reset[] = $row + ['password' => $new_password];
|
||||
}
|
||||
|
||||
logAudit("User", "Edit", "$session_name reset the passwords of " . count($reset) . " agent(s) and forgot their remembered browsers (incident response)");
|
||||
logAudit("User", "Edit", "$session_name reset the passwords of " . count($reset) . " agent(s) and forgot their remembered browsers and passkeys (incident response)");
|
||||
|
||||
// Shown once, not kept - a plain page to read out or copy, and nothing else on it
|
||||
header('Cache-Control: no-store');
|
||||
|
||||
Reference in New Issue
Block a user