Skip to content

Commit f9e799f

Browse files
committed
fix: update random number generation for jitter and token cleanup logic
1 parent 1dc6623 commit f9e799f

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

backend/src/handlers/auth.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ pub async fn login(
346346
};
347347

348348
let jitter = {
349-
use rand::Rng;
350-
rand::thread_rng().gen_range(100..300)
349+
let mut rng = rand::rng();
350+
rng.random_range(100..300)
351351
};
352352
tokio::time::sleep(Duration::from_millis(jitter)).await;
353353

@@ -417,7 +417,12 @@ pub async fn login(
417417

418418
// Bug Fix 3: Probabilistic cleanup of expired tokens (1% chance)
419419
// This prevents the token_blacklist table from growing effectively unbounded.
420-
if rand::thread_rng().gen_bool(0.01) {
420+
let should_cleanup_blacklist = {
421+
let mut rng = rand::rng();
422+
rng.random_bool(0.01)
423+
};
424+
425+
if should_cleanup_blacklist {
421426
let pool_clone = pool.clone();
422427
tokio::spawn(async move {
423428
if let Err(e) = repositories::token_blacklist::cleanup_expired(&pool_clone).await {

backend/src/routes/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use tower_http::services::ServeDir;
2020
/// - **Static Assets**: Serves the `uploads` directory safely via `tower-http`.
2121
pub fn routes(
2222
upload_dir: String,
23-
admin_rate_limit_config: Arc<GovernorConfig<SmartIpKeyExtractor, NoOpMiddleware>>,
23+
_admin_rate_limit_config: Arc<GovernorConfig<SmartIpKeyExtractor, NoOpMiddleware>>,
2424
public_rate_limit_config: Arc<GovernorConfig<SmartIpKeyExtractor, NoOpMiddleware>>,
2525
) -> Router<DbPool> {
2626
Router::new()

0 commit comments

Comments
 (0)