logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: 4ef56c5b65a4d1e7e90a87f1a1a507df523a4b4b
parent 27df2c0ce6c214f36db742af702fc239f80764a7
Author: Lain Soykaf <lain@lain.com>
Date:   Mon, 27 Nov 2023 18:44:11 +0400

ActivityPub.Utils: Only treat object ids as valid while stripping

Diffstat:

Mlib/pleroma/web/activity_pub/utils.ex10++++++----
Mtest/pleroma/web/activity_pub/utils_test.exs10+++++++---
2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex @@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do alias Ecto.UUID alias Pleroma.Activity alias Pleroma.Config + alias Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID alias Pleroma.Maps alias Pleroma.Notification alias Pleroma.Object @@ -852,10 +853,11 @@ defmodule Pleroma.Web.ActivityPub.Utils do [actor | reported_activities] = activity.data["object"] stripped_activities = - Enum.map(reported_activities, fn - act when is_map(act) -> act["id"] - act when is_binary(act) -> act - _other -> nil + Enum.reduce(reported_activities, [], fn act, acc -> + case ObjectID.cast(act) do + {:ok, act} -> [act | acc] + _ -> acc + end end) new_data = put_in(activity.data, ["object"], [actor | stripped_activities]) diff --git a/test/pleroma/web/activity_pub/utils_test.exs b/test/pleroma/web/activity_pub/utils_test.exs @@ -23,6 +23,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do {:ok, activity} = CommonAPI.post(target_account, %{status: "foobar"}) context = Utils.generate_context_id() content = "foobar" + post_id = activity.data["id"] res = Utils.make_flag_data( @@ -30,7 +31,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do actor: reporter, context: context, account: target_account, - statuses: [%{"id" => activity.data["id"]}], + statuses: [%{"id" => post_id}], content: content }, %{} @@ -42,8 +43,11 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do {:ok, activity} = Pleroma.Web.ActivityPub.ActivityPub.insert(res) - Utils.strip_report_status_data(activity) - |> IO.inspect() + [user_id, object | _] = activity.data["object"] + + {:ok, stripped} = Utils.strip_report_status_data(activity) + + assert stripped.data["object"] == [user_id, object["id"]] end end