chore: replace pseudo-random generators with secrets module (#20616)

This commit is contained in:
Bowen Liang 2025-06-06 10:48:28 +08:00 • committed by GitHub
commit c1a13fa553
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 17 additions and 16 deletions

View file

@ -1,4 +1,4 @@
import random
import secrets
from datetime import UTC, datetime, timedelta
from typing import Any, Optional, cast
@ -66,7 +66,7 @@ class WebAppAuthService:
if email is None:
raise ValueError("Email must be provided.")
code = "".join([str(random.randint(0, 9)) for _ in range(6)])
code = "".join([str(secrets.randbelow(exclusive_upper_bound=10)) for _ in range(6)])
token = TokenManager.generate_token(
account=account, email=email, token_type="webapp_email_code_login", additional_data={"code": code}
)