diff options
author | Andrew Morgan <andrew@amorgan.xyz> | 2019-11-06 11:55:00 +0000 |
---|---|---|
committer | Andrew Morgan <andrew@amorgan.xyz> | 2019-11-06 11:55:00 +0000 |
commit | b33c4f7a828e722d6115f73525e0456edb79a90f (patch) | |
tree | 5855850456e8f99c8c641425659c6efe3a500551 /synapse/handlers | |
parent | Fix bug which caused rejected events to be stored with the wrong room state ... (diff) | |
download | synapse-b33c4f7a828e722d6115f73525e0456edb79a90f.tar.xz |
Numeric ID checker now checks @0, don't ratelimit on checking
Diffstat (limited to 'synapse/handlers')
-rw-r--r-- | synapse/handlers/register.py | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py index cff6b0d375..3c142a4395 100644 --- a/synapse/handlers/register.py +++ b/synapse/handlers/register.py @@ -168,6 +168,7 @@ class RegistrationHandler(BaseHandler): Raises: RegistrationError if there was a problem registering. """ + yield self._check_registration_ratelimit(address) yield self.auth.check_auth_blocking(threepid=threepid) password_hash = None @@ -414,6 +415,30 @@ class RegistrationHandler(BaseHandler): ratelimit=False, ) + def _check_registration_ratelimit(self, address): + """A simple helper method to check whether the registration rate limit has been hit + for a given IP address + + Args: + address (str): the IP address used to perform the registration. + + Raises: + LimitExceededError: If the rate limit has been exceeded. + """ + time_now = self.clock.time() + + allowed, time_allowed = self.ratelimiter.can_do_action( + address, + time_now_s=time_now, + rate_hz=self.hs.config.rc_registration.per_second, + burst_count=self.hs.config.rc_registration.burst_count, + ) + + if not allowed: + raise LimitExceededError( + retry_after_ms=int(1000 * (time_allowed - time_now)) + ) + def register_with_store( self, user_id, @@ -446,22 +471,6 @@ class RegistrationHandler(BaseHandler): Returns: Deferred """ - # Don't rate limit for app services - if appservice_id is None and address is not None: - time_now = self.clock.time() - - allowed, time_allowed = self.ratelimiter.can_do_action( - address, - time_now_s=time_now, - rate_hz=self.hs.config.rc_registration.per_second, - burst_count=self.hs.config.rc_registration.burst_count, - ) - - if not allowed: - raise LimitExceededError( - retry_after_ms=int(1000 * (time_allowed - time_now)) - ) - if self.hs.config.worker_app: return self._register_client( user_id=user_id, |