From ba9f945b7b4a676e6cdb1d8bbbe09edb090fb395 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 7 Jul 2019 14:54:04 +0200 Subject: [PATCH] Improve the trash --- app.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index d7be285..4ce826f 100644 --- a/app.py +++ b/app.py @@ -1831,10 +1831,28 @@ 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) + if "type" in data: + # 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) + + if "id" in data: + if DB.trash.find_one({"activity.id": data["id"]}): + # It's already stored in trash, returns early + return Response( + status=422, + headers={"Content-Type": "application/json"}, + response=json.dumps( + { + "error": "failed to verify request (using HTTP signatures or fetching the IRI)" + } + ), + ) + + # Now we can store this activity in the trash for later analysis # Track/store the payload for analysis ip, geoip = _get_ip()