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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user