mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-06-16 19:49:15 -04:00
Add ratelimiting on login (#4821)
Add two ratelimiters on login (per-IP address and per-userID).
This commit is contained in:
parent
3b7ceb2c69
commit
899e523d6d
11 changed files with 259 additions and 37 deletions
|
@ -14,6 +14,8 @@
|
|||
|
||||
import collections
|
||||
|
||||
from synapse.api.errors import LimitExceededError
|
||||
|
||||
|
||||
class Ratelimiter(object):
|
||||
"""
|
||||
|
@ -82,3 +84,13 @@ class Ratelimiter(object):
|
|||
break
|
||||
else:
|
||||
del self.message_counts[key]
|
||||
|
||||
def ratelimit(self, key, time_now_s, rate_hz, burst_count, update=True):
|
||||
allowed, time_allowed = self.can_do_action(
|
||||
key, time_now_s, rate_hz, burst_count, update
|
||||
)
|
||||
|
||||
if not allowed:
|
||||
raise LimitExceededError(
|
||||
retry_after_ms=int(1000 * (time_allowed - time_now_s)),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue