fix: delete login counters that drop to zero

A reserve returned after a KDF budget rejection or 503 left a zero key
in Valkey until the end of the window, so a flood with new usernames
created keys past the address limit and could evict real counters.
SETTLE_SCRIPT and LocalLoginLimiter now delete a counter at zero.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 10:42:25 +03:00
co-authored by Claude Opus 5.5
parent 3f4771c9d9
commit fa5ba51d6a
10 changed files with 163 additions and 30 deletions
+5 -3
View File
@@ -94,11 +94,13 @@ class FakeCache:
return 0
if script == login_limit.SETTLE_SCRIPT:
for key, mode in zip(keys, args, strict=True):
if mode == "del":
count = int(self.values.get(key, "0"))
if mode == "del" or count <= 1:
# дошедший до 0 счётчик удаляется (задача 13.8)
self.values.pop(key, None)
self.expires.pop(key, None)
elif int(self.values.get(key, "0")) > 0:
self.values[key] = str(int(self.values[key]) - 1)
else:
self.values[key] = str(count - 1)
return 1
raise NotImplementedError(script)