fix(auth): reject excess login concurrency before Argon2 work

This commit is contained in:
2026-11-20 20:49:27 +03:00
parent 8326754831
commit eb90f9239b
5 changed files with 138 additions and 8 deletions
+20 -3
View File
@@ -15,8 +15,20 @@ class Passwords:
self.slots = threading.BoundedSemaphore(2)
self.dummy = self.hasher.hash("Synthetic-dummy-password-not-for-login")
def _run(self, function, *args):
if not self.slots.acquire(timeout=5):
def _run(self, function, *args, wait=True):
acquired = (
self.slots.acquire(timeout=5)
if wait
else self.slots.acquire(blocking=False)
)
if not acquired:
if not wait:
raise DomainError(
429,
"rate_limited",
"Authentication concurrency limit exceeded",
{"Retry-After": "1"},
)
raise DomainError(503, "unavailable", "Authentication busy")
try:
return function(*args)
@@ -29,7 +41,12 @@ class Passwords:
def verify(self, *, password: str, encoded: str | None) -> bool:
try:
return (
self._run(self.hasher.verify, encoded or self.dummy, password)
self._run(
self.hasher.verify,
encoded or self.dummy,
password,
wait=False,
)
and encoded is not None
)
except VerificationError, InvalidHashError: