commit: b012bfab5a6640bb6bdec78688ca7dd3dd54aee9
parent ff3cce324ab7f59eb04444cab732c4d8a5ca809d
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Mon, 28 Sep 2020 20:55:44 +0200
Transmogrifier: Check object/activity existance for incoming Delete/Undo
Diffstat:
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -514,10 +514,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
%{"type" => "Delete"} = data,
_options
) do
- with {:ok, activity, _} <-
- Pipeline.common_pipeline(data, local: false) do
+ with {_, %Object{}} <- {:normalize, Object.normalize(data["object"], false)},
+ {:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
{:ok, activity}
else
+ {:normalize, nil} ->
+ {:error, "Unknown object to Delete"}
+
{:error, {:validate, _}} = e ->
# Check if we have a create activity for this
with {:ok, object_id} <- ObjectValidators.ObjectID.cast(data["object"]),
@@ -555,13 +558,17 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def handle_incoming(
%{
"type" => "Undo",
- "object" => %{"type" => type}
+ "object" => %{"type" => type, "id" => act_id}
} = data,
_options
)
when type in ["Like", "EmojiReact", "Announce", "Block"] do
- with {:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
+ with {_, %Activity{}} <- {:normalize, Activity.get_by_id(act_id)},
+ {:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
{:ok, activity}
+ else
+ {:normalize, nil} -> {:error, "Unknown activity to Undo"}
+ e -> e
end
end
@@ -579,7 +586,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|> Map.put("object", data)
|> handle_incoming(options)
else
- _e -> :error
+ nil -> {:error, "Unknown activity to Undo"}
end
end