From 6daf8d6f1601383afac0b3dd265a4c50d342d464 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 7 Jul 2019 14:14:13 +0200 Subject: [PATCH] Drop unknown Delete message --- activitypub.py | 4 +++- app.py | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/activitypub.py b/activitypub.py index b46a36f..8aaf85c 100644 --- a/activitypub.py +++ b/activitypub.py @@ -479,7 +479,9 @@ class MicroblogPubBackend(Backend): question = create.get_object() if question.has_type(ap.ActivityType.QUESTION): now = datetime.now(timezone.utc) - dt = parser.parse(question.closed or question.endTime).astimezone(timezone.utc) + dt = parser.parse(question.closed or question.endTime).astimezone( + timezone.utc + ) minutes = int((dt - now).total_seconds() / 60) Tasks.fetch_remote_question(create.id, minutes) diff --git a/app.py b/app.py index ce0efea..d7be285 100644 --- a/app.py +++ b/app.py @@ -1817,7 +1817,7 @@ def inbox(): "failed to verify request, trying to verify the payload by fetching the remote" ) try: - data = get_backend().fetch_iri(data["id"]) + remote_data = get_backend().fetch_iri(data["id"]) except ActivityGoneError: # XXX Mastodon sends Delete activities that are not dereferencable, it's the actor url with #delete # appended, so an `ActivityGoneError` kind of ensure it's "legit" @@ -1831,6 +1831,11 @@ def inbox(): except Exception: logger.exception(f"failed to fetch remote for payload {data!r}") + # Friendica does not returns a 410, but a 302 that redirect to an HTML page + if ap._has_type(data["type"], ActivityType.DELETE): + logger.info(f"received a Delete for an unknown actor {data!r}, drop it") + return Response(status=201) + # Track/store the payload for analysis ip, geoip = _get_ip() @@ -1856,6 +1861,9 @@ def inbox(): } ), ) + + # We fetched the remote data successfully + data = remote_data print(data) activity = ap.parse_activity(data) logger.debug(f"inbox activity={activity}/{data}")