mirror of
https://github.com/mailcow/mailcow-dockerized.git
synced 2026-11-16 05:10:15 +00:00
fix(web): post WebAuthn TFA enrollment through the JSON API
The forced TFA enrollment form submitted the raw credential JSON in the 'token' field, which set_tfa()'s webauthn case never reads. It expects the parsed \['registration'] object that only the JSON API builds, so the form POST inserted a row with an empty keyHandle and a NULL publicKey while still reporting success. Every WebAuthn 2FA login then failed, because webauthn-tfa-get-args sent an empty credential id in allowCredentials. - base.twig: POST the attestation to /api/v1/add/webauthn-tfa-registration like the regular WebAuthn modal does - functions.inc.php: refuse incomplete WebAuthn registrations - lang.en-gb.json: message for the new guard
This commit is contained in:
1 parent
8cd231c9b9
commit
d93f32072e
3 files changed
+30
-11
No files matched your search
@@ -1389,6 +1389,18 @@ function set_tfa($_data) {
|
|||||||
case "webauthn":
|
case "webauthn":
|
||||||
$key_id = (!isset($_data["key_id"])) ? 'unidentified' : $_data["key_id"];
|
$key_id = (!isset($_data["key_id"])) ? 'unidentified' : $_data["key_id"];
|
||||||
|
|
||||||
|
// Refuse incomplete WebAuthn registrations. Without this guard a request
|
||||||
|
// that does not contain the parsed credential data (e.g. a plain form
|
||||||
|
// POST) would silently insert an empty keyHandle while reporting success.
|
||||||
|
if (empty($_data['registration']) || empty($_data['registration']->credentialId)) {
|
||||||
|
$_SESSION['return'][] = array(
|
||||||
|
'type' => 'danger',
|
||||||
|
'log' => array(__FUNCTION__, $_data_log),
|
||||||
|
'msg' => 'webauthn_registration_failed'
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$stmt = $pdo->prepare("INSERT INTO `tfa` (`username`, `key_id`, `authmech`, `keyHandle`, `publicKey`, `certificate`, `counter`, `active`)
|
$stmt = $pdo->prepare("INSERT INTO `tfa` (`username`, `key_id`, `authmech`, `keyHandle`, `publicKey`, `certificate`, `counter`, `active`)
|
||||||
VALUES (?, ?, 'webauthn', ?, ?, ?, ?, '1')");
|
VALUES (?, ?, 'webauthn', ?, ?, ?, ?, '1')");
|
||||||
$stmt->execute(array(
|
$stmt->execute(array(
|
||||||
|
|||||||
@@ -1249,6 +1249,7 @@
|
|||||||
"u2f_deprecated": "It seems that your Key was registered using the deprecated U2F method. We will deactivate Two-Factor-Authenticaiton for you and delete your Key.",
|
"u2f_deprecated": "It seems that your Key was registered using the deprecated U2F method. We will deactivate Two-Factor-Authenticaiton for you and delete your Key.",
|
||||||
"u2f_deprecated_important": "Please register your Key in the admin panel with the new WebAuthn method.",
|
"u2f_deprecated_important": "Please register your Key in the admin panel with the new WebAuthn method.",
|
||||||
"webauthn": "WebAuthn authentication",
|
"webauthn": "WebAuthn authentication",
|
||||||
|
"webauthn_registration_failed": "WebAuthn registration failed. The credential could not be verified, please try again.",
|
||||||
"waiting_usb_auth": "<i>Waiting for USB device...</i><br><br>Please tap the button on your USB device now.",
|
"waiting_usb_auth": "<i>Waiting for USB device...</i><br><br>Please tap the button on your USB device now.",
|
||||||
"waiting_usb_register": "<i>Waiting for USB device...</i><br><br>Please enter your password above and confirm your registration by tapping the button on your USB device.",
|
"waiting_usb_register": "<i>Waiting for USB device...</i><br><br>Please enter your password above and confirm your registration by tapping the button on your USB device.",
|
||||||
"yubi_otp": "Yubico OTP authentication"
|
"yubi_otp": "Yubico OTP authentication"
|
||||||
|
|||||||
@@ -415,18 +415,24 @@ function recursiveBase64StrToArrayBuffer(obj) {
|
|||||||
return navigator.credentials.create(json);
|
return navigator.credentials.create(json);
|
||||||
}).then(function(cred) {
|
}).then(function(cred) {
|
||||||
return {
|
return {
|
||||||
id: cred.id,
|
clientDataJSON: arrayBufferToBase64(cred.response.clientDataJSON),
|
||||||
rawId: arrayBufferToBase64(cred.rawId),
|
attestationObject: arrayBufferToBase64(cred.response.attestationObject),
|
||||||
response: {
|
key_id: keyId,
|
||||||
attestationObject: arrayBufferToBase64(cred.response.attestationObject),
|
tfa_method: 'webauthn',
|
||||||
clientDataJSON: arrayBufferToBase64(cred.response.clientDataJSON)
|
confirm_password: ''
|
||||||
},
|
|
||||||
type: cred.type
|
|
||||||
};
|
};
|
||||||
}).then(function(credData) {
|
}).then(JSON.stringify).then(function(credentialData) {
|
||||||
$('#setup_webauthn_register_data').val(JSON.stringify(credData));
|
// send the attestation to the JSON API, like the regular WebAuthn modal does,
|
||||||
$('#setup_webauthn_reg_form input[name=set_tfa]').val('1');
|
// so that the credential is parsed and stored correctly
|
||||||
$('#setup_webauthn_reg_form').submit();
|
return window.fetch('/api/v1/add/webauthn-tfa-registration', {method: 'POST', body: credentialData, cache: 'no-cache'});
|
||||||
|
}).then(function(response) {
|
||||||
|
return response.json();
|
||||||
|
}).then(function(json) {
|
||||||
|
if (json.success) {
|
||||||
|
window.location = window.location.href.split('#')[0];
|
||||||
|
} else {
|
||||||
|
throw new Error(json.msg);
|
||||||
|
}
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
$('#setup_webauthn_return_code').show().text(err.message || 'Registration failed');
|
$('#setup_webauthn_return_code').show().text(err.message || 'Registration failed');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user