Advisory

GHSA-v6pg-v89r-w8wr

Details, part 2 of 2. The advisory

Details

if success {
fmt.Printf("\n\nSuccess: Found OTP = %s\n", otpStr)
cancel()
return
}
}
}(start, end)
}

wg.Wait()
fmt.Println("Brute-force attempt finished.")
}

<img width="997" height="301" alt="image" src="https://github.com/user-attachments/assets/61486bb6-302b-4edb-87b7-d229bbd33380" />

### Impact

An attacker who gains access to a user&rsquo;s account can exploit this bypass to perform protected actions such as accessing the user&rsquo;s API key or deleting the user&rsquo;s accounts and organisations.

### Remediation

The simplest fix is to ensure the updated number of attempts is persisted by calling `pa.data = pa_data.to_json()` before calling `pa.save(conn)`. However this still leaves open the possibility of an attacker requesting an OTP code, exhausting their six attempts and then requesting a new code to try. This attack succeeds with probability

```math
1 - \left(1 - \frac{6}{10^L}\right)^n,

which becomes non-neglible as $n$ increases.

Therefore the best approach might be to enforce a delay like this, to ensure that all rate limits are ultimately tied back to time:

diff --git a/src/api/core/two_factor/protected_actions.rs b/src/api/core/two_factor/protected_actions.rs
index 5e4a65be..aa9cb8f6 100644
--- a/src/api/core/two_factor/protected_actions.rs
+++ b/src/api/core/two_factor/protected_actions.rs
@@ -66,7 +66,18 @@ async fn request_otp(headers: Headers, mut conn: DbConn) -> EmptyResult {
     if let Some(pa) =
         TwoFactor::find_by_user_and_type(&user.uuid, TwoFactorType::ProtectedActions as i32, &mut conn).await
     {
-        pa.delete(&mut conn).await?;
+        let pa_data = ProtectedActionData::from_json(&pa.data)?;
+        let token_sent = DateTime::from_timestamp(pa_data.token_sent, 0)
+            .expect("Protected Action token timestamp invalid")
+            .naive_utc();
+        let elapsed = Utc::now().naive_utc() - token_sent;
+        let delay = TimeDelta::seconds(20);
+
+        if elapsed < delay {
+            err!(format!("Please wait {} seconds before requesting another code.", (delay - elapsed).num_seconds()));
+        } else {
+            pa.delete(&mut conn).await?;
+        }
     }

     let generated_token = crypto::generate_email_token(CONFIG.email_token_size());
@@ -131,6 +142,7 @@ pub async fn validate_protected_action_otp(
     }

     if !crypto::ct_eq(&pa_data.token, otp) {
+        pa.data = pa_data.to_json();
         pa.save(conn).await?;
         err!("Token is invalid")
     }

Sources & licences