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

This commit is contained in:
Lain Soykaf 2023-11-27 18:44:11 +04:00
parent 27df2c0ce6
commit 4ef56c5b65
2 changed files with 13 additions and 7 deletions

View File

@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
alias Ecto.UUID alias Ecto.UUID
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Config alias Pleroma.Config
alias Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID
alias Pleroma.Maps alias Pleroma.Maps
alias Pleroma.Notification alias Pleroma.Notification
alias Pleroma.Object alias Pleroma.Object
@ -852,10 +853,11 @@ defmodule Pleroma.Web.ActivityPub.Utils do
[actor | reported_activities] = activity.data["object"] [actor | reported_activities] = activity.data["object"]
stripped_activities = stripped_activities =
Enum.map(reported_activities, fn Enum.reduce(reported_activities, [], fn act, acc ->
act when is_map(act) -> act["id"] case ObjectID.cast(act) do
act when is_binary(act) -> act {:ok, act} -> [act | acc]
_other -> nil _ -> acc
end
end) end)
new_data = put_in(activity.data, ["object"], [actor | stripped_activities]) new_data = put_in(activity.data, ["object"], [actor | stripped_activities])

View File

@ -23,6 +23,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
{:ok, activity} = CommonAPI.post(target_account, %{status: "foobar"}) {:ok, activity} = CommonAPI.post(target_account, %{status: "foobar"})
context = Utils.generate_context_id() context = Utils.generate_context_id()
content = "foobar" content = "foobar"
post_id = activity.data["id"]
res = res =
Utils.make_flag_data( Utils.make_flag_data(
@ -30,7 +31,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
actor: reporter, actor: reporter,
context: context, context: context,
account: target_account, account: target_account,
statuses: [%{"id" => activity.data["id"]}], statuses: [%{"id" => post_id}],
content: content content: content
}, },
%{} %{}
@ -42,8 +43,11 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
{:ok, activity} = Pleroma.Web.ActivityPub.ActivityPub.insert(res) {:ok, activity} = Pleroma.Web.ActivityPub.ActivityPub.insert(res)
Utils.strip_report_status_data(activity) [user_id, object | _] = activity.data["object"]
|> IO.inspect()
{:ok, stripped} = Utils.strip_report_status_data(activity)
assert stripped.data["object"] == [user_id, object["id"]]
end end
end end