relay: never relay an object back to the instance which hosts it

This commit is contained in:
kaniini 2018-11-20 00:42:31 +00:00
parent b607e382cb
commit 3af63d4d9f

View file

@ -147,11 +147,14 @@ def strip_html(data):
return cgi.escape(no_tags) return cgi.escape(no_tags)
def distill_inboxes(actor): def distill_inboxes(actor, object_id):
global DATABASE global DATABASE
origin_hostname = urlsplit(object_id).hostname
inbox = get_actor_inbox(actor) inbox = get_actor_inbox(actor)
targets = [target for target in DATABASE.get('relay-list', []) if target != inbox] targets = [target for target in DATABASE.get('relay-list', []) if target != inbox]
targets = [target for target in targets if urlsplit(target).hostname != origin_hostname]
assert inbox not in targets assert inbox not in targets
@ -194,7 +197,7 @@ async def handle_relay(actor, data, request):
logging.debug('>> relay: %r', message) logging.debug('>> relay: %r', message)
inboxes = distill_inboxes(actor) inboxes = distill_inboxes(actor, object_id)
futures = [push_message_to_actor({'inbox': inbox}, message, 'https://{}/actor#main-key'.format(request.host)) for inbox in inboxes] futures = [push_message_to_actor({'inbox': inbox}, message, 'https://{}/actor#main-key'.format(request.host)) for inbox in inboxes]
asyncio.ensure_future(asyncio.gather(*futures)) asyncio.ensure_future(asyncio.gather(*futures))