Do not federate undo->block activities

the :do_not_federate checks were omitted from the undo pipeline,
which could lead to them federating.

this commit enforces :outgoing_blocks on undos as well - and
any existing value of :do_not_federate is preserved, if one exists

Fixes #957
This commit is contained in:
Floatingghost 2025-08-02 09:47:32 +01:00
parent 5beb286bff
commit eca7ed572b
2 changed files with 26 additions and 0 deletions

View file

@ -63,10 +63,16 @@ def validate(%{"type" => "Undo"} = object, meta) do
|> Ecto.Changeset.apply_action(:insert) do
object = stringify_keys(object)
undone_object = Activity.get_by_ap_id(object["object"])
outgoing_blocks = Pleroma.Config.get([:activitypub, :outgoing_blocks])
# if we're undoing a block, and do not permit federating that:
do_not_federate =
Keyword.get(meta, :do_not_federate) ||
(Map.get(undone_object.data, "type") == "Block" && !outgoing_blocks)
meta =
meta
|> Keyword.put(:object_data, undone_object.data)
|> Keyword.put(:do_not_federate, do_not_federate)
{:ok, object, meta}
end

View file

@ -128,6 +128,26 @@ test "it works even without an existing block activity" do
assert {:ok, :no_activity} == CommonAPI.unblock(blocker, blocked)
refute User.blocks?(blocker, blocked)
end
test "it unblocks and does not federate if outgoing blocks are disabled" do
clear_config([:instance, :federating], true)
clear_config([:activitypub, :outgoing_blocks], false)
blocked = insert(:user)
blocker = insert(:user)
with_mock Pleroma.Web.Federator,
publish: fn _ -> nil end do
assert {:ok, block} = CommonAPI.block(blocker, blocked)
assert block.local
assert User.blocks?(blocker, blocked)
assert {:ok, unblock} = CommonAPI.unblock(blocker, blocked)
assert unblock.local
refute User.blocks?(blocker, blocked)
assert_not_called(Pleroma.Web.Federator.publish(:_))
end
end
end
describe "deletion" do