Skip to content

Commit

Permalink
Log if ActivityPub inbox request is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
LoanR committed Nov 21, 2024
1 parent 48b24e9 commit 25608b8
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions pod/activitypub/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,29 @@ def inbox(request, username=None):
https://www.w3.org/TR/activitypub/#inbox
"""

data = json.loads(request.body.decode()) if request.body else None
logger.warning("inbox query: %s", json.dumps(data, indent=True))

if (
data["type"] in ("Announce", "Update", "Delete")
and not settings.TEST_SETTINGS
and not check_signatures(request)
):
return HttpResponse("Signature could not be verified", status=403)

if activitypub_task := TYPE_TASK.get(data["type"], None):
activitypub_task.delay(username, data)
else:
logger.debug("Ignoring inbox action: %s", data["type"])

return HttpResponse(status=204)
try:
data = json.loads(request.body.decode())
logger.warning("inbox query: %s", json.dumps(data, indent=True))

if (
data["type"] in ("Announce", "Update", "Delete")
and not settings.TEST_SETTINGS
and not check_signatures(request)
):
return HttpResponse("Signature could not be verified", status=403)

if activitypub_task := TYPE_TASK.get(data["type"], None):
activitypub_task.delay(username, data)
else:
logger.debug("Ignoring inbox action: %s", data["type"])

return HttpResponse(status=204)
except (AttributeError, KeyError, UnicodeError, ValueError) as err:
logger.error("ActivityPub inbox request body badly formatted and unusable: %s" % err)
return HttpResponse(status=422)
except Exception as err:
logger.error("ActivityPub inbox request error: %s" % err)
return HttpResponse(status=400)


@csrf_exempt
Expand Down

0 comments on commit 25608b8

Please sign in to comment.