make software blocklist configurable

This commit is contained in:
Izalia Mae 2020-12-04 02:34:40 -05:00
parent f0e08f26b3
commit bc0914b5c1
3 changed files with 10 additions and 5 deletions

View File

@ -21,4 +21,10 @@ ap:
whitelist: whitelist:
- 'good-instance.example.com' - 'good-instance.example.com'
- 'another.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'

View File

@ -23,7 +23,7 @@ def load_config():
'port': int(yaml_file.get('port', 8080)), 'port': int(yaml_file.get('port', 8080)),
'note': yaml_file.get('note', 'Make a note about your instance here.'), 'note': yaml_file.get('note', 'Make a note about your instance here.'),
'ap': { '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', []), 'blocked_instances': yaml_file['ap'].get('blocked_instances', []),
'host': yaml_file['ap'].get('host', 'localhost'), 'host': yaml_file['ap'].get('host', 'localhost'),
'whitelist': yaml_file['ap'].get('whitelist', []), 'whitelist': yaml_file['ap'].get('whitelist', []),
@ -35,7 +35,6 @@ def load_config():
CONFIG = load_config() CONFIG = load_config()
from .http_signatures import http_signatures_middleware from .http_signatures import http_signatures_middleware

View File

@ -318,10 +318,10 @@ async def inbox(request):
data = await request.json() data = await request.json()
instance = urlsplit(data['actor']).hostname instance = urlsplit(data['actor']).hostname
if AP_CONFIG['block_relays']: if AP_CONFIG['blocked_software']:
software = await fetch_nodeinfo(instance) 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') raise aiohttp.web.HTTPUnauthorized(body='relays have been blocked', content_type='text/plain')
if 'actor' not in data or not request['validated']: if 'actor' not in data or not request['validated']: