Do not allow posts from blocked domains in

Fixes #172
This commit is contained in:
Andrew Godwin 2022-12-18 09:58:24 -07:00
parent 5d6ff57b5f
commit b8dca2b71f

View file

@ -712,7 +712,8 @@ class Post(StatorModel):
Retrieves a Post instance by its ActivityPub JSON object. Retrieves a Post instance by its ActivityPub JSON object.
Optionally creates one if it's not present. Optionally creates one if it's not present.
Raises KeyError if it's not found and create is False. Raises DoesNotExist if it's not found and create is False,
or it's from a blocked domain.
""" """
# Do we have one with the right ID? # Do we have one with the right ID?
created = False created = False
@ -724,6 +725,9 @@ class Post(StatorModel):
if create: if create:
# Resolve the author # Resolve the author
author = Identity.by_actor_uri(data["attributedTo"], create=create) author = Identity.by_actor_uri(data["attributedTo"], create=create)
# If the post is from a blocked domain, stop and drop
if author.domain.blocked:
raise cls.DoesNotExist("Post is from a blocked domain")
post = cls.objects.create( post = cls.objects.create(
object_uri=data["id"], object_uri=data["id"],
author=author, author=author,