SimplePolicy: filter nested objects
authorAlex Gleason <alex@alexgleason.me>
Thu, 18 Mar 2021 20:31:50 +0000 (15:31 -0500)
committerAlex Gleason <alex@alexgleason.me>
Fri, 30 Apr 2021 19:20:37 +0000 (14:20 -0500)
lib/pleroma/web/activity_pub/mrf/simple_policy.ex
test/pleroma/web/activity_pub/mrf/simple_policy_test.exs

index bb3838d2c18f009efefee8c2f18d1f373fac0abb..b3e5d814d9f10c5653fc2aa16251dd11dd66540f 100644 (file)
@@ -181,6 +181,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
 
   defp check_banner_removal(_actor_info, object), do: {:ok, object}
 
+  defp check_object(%{"object" => object} = activity) when is_map(object) do
+    with {:ok, _object} <- filter(object) do
+      {:ok, activity}
+    end
+  end
+
+  defp check_object(object), do: {:ok, object}
+
   @impl true
   def filter(%{"type" => "Delete", "actor" => actor} = object) do
     %{host: actor_host} = URI.parse(actor)
@@ -206,7 +214,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
          {:ok, object} <- check_media_nsfw(actor_info, object),
          {:ok, object} <- check_ftl_removal(actor_info, object),
          {:ok, object} <- check_followers_only(actor_info, object),
-         {:ok, object} <- check_report_removal(actor_info, object) do
+         {:ok, object} <- check_report_removal(actor_info, object),
+         {:ok, object} <- check_object(object) do
       {:ok, object}
     else
       {:reject, nil} -> {:reject, "[SimplePolicy]"}
index f48e5b39bcebb22d59939c5a089fb83445aeb6aa..b6d9f2ded20b9070880e0fae204ca78c89439769 100644 (file)
@@ -260,6 +260,18 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
 
       assert {:reject, _} = SimplePolicy.filter(remote_user)
     end
+
+    test "reject Announce when object would be rejected" do
+      clear_config([:mrf_simple, :reject], ["blocked.tld"])
+
+      announce = %{
+        "type" => "Announce",
+        "actor" => "https://okay.tld/users/alice",
+        "object" => %{"type" => "Note", "actor" => "https://blocked.tld/users/bob"}
+      }
+
+      assert {:reject, _} = SimplePolicy.filter(announce)
+    end
   end
 
   describe "when :followers_only" do