Skip to content

Commit

Permalink
feat(labrinth): totp skew (modrinth#2887)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erb3 authored Nov 19, 2024
1 parent 8cd77ad commit 4685330
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions apps/labrinth/src/routes/internal/flows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1678,26 +1678,26 @@ async fn validate_2fa_code(
.map_err(|_| AuthenticationError::InvalidCredentials)?,
)
.map_err(|_| AuthenticationError::InvalidCredentials)?;
let token = totp
.generate_current()
.map_err(|_| AuthenticationError::InvalidCredentials)?;

const TOTP_NAMESPACE: &str = "used_totp";
let mut conn = redis.connect().await?;

// Check if TOTP has already been used
if conn
.get(TOTP_NAMESPACE, &format!("{}-{}", token, user_id.0))
.get(TOTP_NAMESPACE, &format!("{}-{}", input, user_id.0))
.await?
.is_some()
{
return Err(AuthenticationError::InvalidCredentials);
}

if input == token {
if totp
.check_current(input.as_str())
.map_err(|_| AuthenticationError::InvalidCredentials)?
{
conn.set(
TOTP_NAMESPACE,
&format!("{}-{}", token, user_id.0),
&format!("{}-{}", input, user_id.0),
"",
Some(60),
)
Expand Down

0 comments on commit 4685330

Please sign in to comment.