logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: d0ef110b6cf77d02e8aee34acfbf29ec4f0db036
parent 0bb05812bf3255beedf54fa71a8605f7051d6e4b
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:

Mlib/pleroma/web/activity_pub/transmogrifier.ex17++++++++++++-----
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