From bc0914b5c1cc2fa43006d9fb2f1df2358b46e30d Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Fri, 4 Dec 2020 02:34:40 -0500 Subject: [PATCH] make software blocklist configurable --- relay.yaml.example | 8 +++++++- relay/__init__.py | 3 +-- relay/actor.py | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/relay.yaml.example b/relay.yaml.example index 0f7f949..68f0016 100644 --- a/relay.yaml.example +++ b/relay.yaml.example @@ -21,4 +21,10 @@ ap: whitelist: - 'good-instance.example.com' - 'another.good-instance.example.com' - block_relays: false + # uncomment the lines below to prevent certain activitypub software from posting + # to the relay (all known relays by default). this uses the software name in nodeinfo + #blocked_software: + #- 'activityrelay' + #- 'aoderelay' + #- 'social.seattle.wa.us-relay' + #- 'unciarelay' diff --git a/relay/__init__.py b/relay/__init__.py index cad19ce..3785de6 100644 --- a/relay/__init__.py +++ b/relay/__init__.py @@ -23,7 +23,7 @@ def load_config(): 'port': int(yaml_file.get('port', 8080)), 'note': yaml_file.get('note', 'Make a note about your instance here.'), 'ap': { - 'block_relays': yaml_file['ap'].get('block_relays', False), + 'blocked_software': [v.lower() for v in yaml_file['ap'].get('blocked_software', [])], 'blocked_instances': yaml_file['ap'].get('blocked_instances', []), 'host': yaml_file['ap'].get('host', 'localhost'), 'whitelist': yaml_file['ap'].get('whitelist', []), @@ -35,7 +35,6 @@ def load_config(): CONFIG = load_config() - from .http_signatures import http_signatures_middleware diff --git a/relay/actor.py b/relay/actor.py index d0e1f8b..4264cca 100644 --- a/relay/actor.py +++ b/relay/actor.py @@ -318,10 +318,10 @@ async def inbox(request): data = await request.json() instance = urlsplit(data['actor']).hostname - if AP_CONFIG['block_relays']: + if AP_CONFIG['blocked_software']: software = await fetch_nodeinfo(instance) - if software and 'relay' in software.lower(): + if software and software.lower() in AP_CONFIG['blocked_software']: raise aiohttp.web.HTTPUnauthorized(body='relays have been blocked', content_type='text/plain') if 'actor' not in data or not request['validated']: