From aa79a27840275740b470219c41d6ac53e5a91b66 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tristan=20Mah=C3=A9?= Date: Wed, 31 Oct 2018 12:29:30 -0700 Subject: [PATCH] very simple blocklist --- relay.yaml.example | 4 ++++ relay/actor.py | 5 ++++- relay/database.py | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/relay.yaml.example b/relay.yaml.example index 22195d6..4f0b69c 100644 --- a/relay.yaml.example +++ b/relay.yaml.example @@ -14,3 +14,7 @@ ap: # this is used for generating activitypub messages, as well as instructions for # linking AP identities. it should be an SSL-enabled domain reachable by https. host: 'relay.example.com' + blocked_instances: + - 'bad-instance.example.com' + - 'another-bad-instance.example.com' + diff --git a/relay/actor.py b/relay/actor.py index b8ff942..49abc38 100644 --- a/relay/actor.py +++ b/relay/actor.py @@ -32,7 +32,7 @@ from . import app, CONFIG from .remote_actor import fetch_actor -AP_CONFIG = CONFIG.get('ap', {'host': 'localhost'}) +AP_CONFIG = CONFIG.get('ap', {'host': 'localhost','blocked_instances':[]}) async def actor(request): @@ -186,6 +186,9 @@ async def handle_follow(actor, data, request): following = DATABASE.get('relay-list', []) inbox = get_actor_inbox(actor) + if re.search('https://(.*)/inbox',inbox).group(1) in AP_CONFIG['blocked_instances']: + return + if inbox not in following: following += [inbox] DATABASE['relay-list'] = following diff --git a/relay/database.py b/relay/database.py index 857af93..b60f9bb 100644 --- a/relay/database.py +++ b/relay/database.py @@ -13,6 +13,11 @@ except: logging.info('No database was found, making a new one.') DATABASE = {} +following = DATABASE.get('relay-list', []) +for inbox in following: + if re.search('https://(.*)/inbox',inbox).group(1) in CONFIG['ap']['blocked_instances']: + following.remove(inbox) + DATABASE['relay-list'] = following async def database_save(): while True: -- 2.20.1