Skip to content

Commit 8e7eeab

Browse files
authored
Fix WebauthN issue with Software Keys (#6168)
The check if the token used was a known valid token also checked if it needed to be updated. This check caused always caused an issue with tokens which do not need or want to be updated. Since the cred_ids are already checked and deemed valid we only need to check if there is an updated needed. Their already is a function for this `update_credential`, which returns `Some(true)` if this was the case. So, only update the records if that is the case, else do not update anything. Also, used constant time compare to check and validate the cred_id's. Fixes #6154 Signed-off-by: BlackDex <[email protected]>
1 parent e35c6f8 commit 8e7eeab

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/api/core/two_factor/webauthn.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
EmptyResult, JsonResult, PasswordOrOtpData,
55
},
66
auth::Headers,
7+
crypto::ct_eq,
78
db::{
89
models::{EventType, TwoFactor, TwoFactorType, UserId},
910
DbConn,
@@ -434,12 +435,14 @@ pub async fn validate_webauthn_login(
434435
let authentication_result = webauthn.finish_securitykey_authentication(&rsp, &state)?;
435436

436437
for reg in &mut registrations {
437-
if reg.credential.cred_id() == authentication_result.cred_id() && authentication_result.needs_update() {
438-
reg.credential.update_credential(&authentication_result);
439-
440-
TwoFactor::new(user_id.clone(), TwoFactorType::Webauthn, serde_json::to_string(&registrations)?)
441-
.save(conn)
442-
.await?;
438+
if ct_eq(reg.credential.cred_id(), authentication_result.cred_id()) {
439+
// If the cred id matches and the credential is updated, Some(true) is returned
440+
// In those cases, update the record, else leave it alone
441+
if reg.credential.update_credential(&authentication_result) == Some(true) {
442+
TwoFactor::new(user_id.clone(), TwoFactorType::Webauthn, serde_json::to_string(&registrations)?)
443+
.save(conn)
444+
.await?;
445+
}
443446
return Ok(());
444447
}
445448
}

0 commit comments

Comments
 (0)