diff options
author | Will Hunt <will@half-shot.uk> | 2018-06-25 17:16:01 +0100 |
---|---|---|
committer | Will Hunt <will@half-shot.uk> | 2018-06-25 17:16:01 +0100 |
commit | 8d926d78ff4b4235e0429d73fbdc0993faf9cb05 (patch) | |
tree | 8e9caba7169c1f30682eb7895e289c6ce020069a | |
parent | Need to pass reactor to endpoint fac (diff) | |
download | synapse-8d926d78ff4b4235e0429d73fbdc0993faf9cb05.tar.xz |
Add app_service_server_blacklist option
-rw-r--r-- | synapse/config/appservice.py | 13 | ||||
-rw-r--r-- | synapse/handlers/appservice.py | 11 |
2 files changed, 24 insertions, 0 deletions
diff --git a/synapse/config/appservice.py b/synapse/config/appservice.py index 277305e184..e3d43b3aa2 100644 --- a/synapse/config/appservice.py +++ b/synapse/config/appservice.py @@ -19,6 +19,7 @@ from synapse.types import UserID import yaml import logging +import re from six import string_types from six.moves.urllib import parse as urlparse @@ -31,6 +32,18 @@ class AppServiceConfig(Config): def read_config(self, config): self.app_service_config_files = config.get("app_service_config_files", []) self.notify_appservices = config.get("notify_appservices", True) + s_blacklist = config.get( + "app_service_server_blacklist", [] + ) + try: + self.app_service_server_blacklist = [ + re.compile(x) for x in s_blacklist + ] + except re.error as ex: + raise ConfigError( + "Could not compile regex in app_service_server_blacklist: %s", + ex.message + ) def default_config(cls, **kwargs): return """\ diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py index 1c29c43a83..0d04c704d7 100644 --- a/synapse/handlers/appservice.py +++ b/synapse/handlers/appservice.py @@ -23,6 +23,8 @@ from synapse.util.metrics import Measure from synapse.util.logcontext import ( make_deferred_yieldable, run_in_background, ) +from synapse.types import get_domain_from_id + from prometheus_client import Counter import logging @@ -52,6 +54,7 @@ class ApplicationServicesHandler(object): self.scheduler = hs.get_application_service_scheduler() self.started_scheduler = False self.clock = hs.get_clock() + self.server_blacklist = hs.config.app_service_server_blacklist self.notify_appservices = hs.config.notify_appservices self.current_max = 0 @@ -93,6 +96,14 @@ class ApplicationServicesHandler(object): @defer.inlineCallbacks def handle_event(event): + ev_domain = get_domain_from_id(event.event_id) + if any(srv_re.match(ev_domain) is not None for srv_re in self.server_blacklist): + logger.info( + "Ignoring %s from %s, matches server blacklist", + event.event_id, + ev_domain + ) + return # Gather interested services services = yield self._get_services_for_event(event) if len(services) == 0: |