commit: d99306593aaf5f1a430f85a7614eaf28898cd7e1
parent eba6dca829dd34ab3a951c08f46ff3274293c244
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"]),
@@ -558,13 +561,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
@@ -582,7 +589,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