diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2020-08-20 15:42:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-20 15:42:58 -0400 |
commit | 3f91638da6ea0aeaf789ddc8ca1e624a11b7ebb2 (patch) | |
tree | a8630b302bda863880f4a763e179b5982567a0c8 /synapse/events/spamcheck.py | |
parent | Stop shadow-banned users from sending invites. (#8095) (diff) | |
download | synapse-3f91638da6ea0aeaf789ddc8ca1e624a11b7ebb2.tar.xz |
Allow denying or shadow banning registrations via the spam checker (#8034)
Diffstat (limited to 'synapse/events/spamcheck.py')
-rw-r--r-- | synapse/events/spamcheck.py | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/synapse/events/spamcheck.py b/synapse/events/spamcheck.py index 1ffc9525d1..a7cddac974 100644 --- a/synapse/events/spamcheck.py +++ b/synapse/events/spamcheck.py @@ -15,9 +15,10 @@ # limitations under the License. import inspect -from typing import Any, Dict, List +from typing import Any, Dict, List, Optional, Tuple -from synapse.spam_checker_api import SpamCheckerApi +from synapse.spam_checker_api import RegistrationBehaviour, SpamCheckerApi +from synapse.types import Collection MYPY = False if MYPY: @@ -160,3 +161,33 @@ class SpamChecker(object): return True return False + + def check_registration_for_spam( + self, + email_threepid: Optional[dict], + username: Optional[str], + request_info: Collection[Tuple[str, str]], + ) -> RegistrationBehaviour: + """Checks if we should allow the given registration request. + + Args: + email_threepid: The email threepid used for registering, if any + username: The request user name, if any + request_info: List of tuples of user agent and IP that + were used during the registration process. + + Returns: + Enum for how the request should be handled + """ + + for spam_checker in self.spam_checkers: + # For backwards compatibility, only run if the method exists on the + # spam checker + checker = getattr(spam_checker, "check_registration_for_spam", None) + if checker: + behaviour = checker(email_threepid, username, request_info) + assert isinstance(behaviour, RegistrationBehaviour) + if behaviour != RegistrationBehaviour.ALLOW: + return behaviour + + return RegistrationBehaviour.ALLOW |