SimplePolicy: filter string Objects
authorAlex Gleason <alex@alexgleason.me>
Thu, 29 Apr 2021 16:51:49 +0000 (11:51 -0500)
committerAlex Gleason <alex@alexgleason.me>
Fri, 30 Apr 2021 19:20:54 +0000 (14:20 -0500)
lib/pleroma/web/activity_pub/mrf/simple_policy.ex
test/pleroma/web/activity_pub/mrf/simple_policy_test.exs

index b3e5d814d9f10c5653fc2aa16251dd11dd66540f..b07d70401391b3bdc76c2d8fda7219fe3fe51eea 100644 (file)
@@ -181,7 +181,7 @@ 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
+  defp check_object(%{"object" => object} = activity) do
     with {:ok, _object} <- filter(object) do
       {:ok, activity}
     end
@@ -240,6 +240,19 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
     end
   end
 
+  def filter(object) when is_binary(object) do
+    uri = URI.parse(object)
+
+    with {:ok, object} <- check_accept(uri, object),
+         {:ok, object} <- check_reject(uri, object) do
+      {:ok, object}
+    else
+      {:reject, nil} -> {:reject, "[SimplePolicy]"}
+      {:reject, _} = e -> e
+      _ -> {:reject, "[SimplePolicy]"}
+    end
+  end
+
   def filter(object), do: {:ok, object}
 
   @impl true
index b6d9f2ded20b9070880e0fae204ca78c89439769..8024a24594c415efc774060ffe0b048bd7a33720 100644 (file)
@@ -272,6 +272,18 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
 
       assert {:reject, _} = SimplePolicy.filter(announce)
     end
+
+    test "reject by URI object" do
+      clear_config([:mrf_simple, :reject], ["blocked.tld"])
+
+      announce = %{
+        "type" => "Announce",
+        "actor" => "https://okay.tld/users/alice",
+        "object" => "https://blocked.tld/activities/1"
+      }
+
+      assert {:reject, _} = SimplePolicy.filter(announce)
+    end
   end
 
   describe "when :followers_only" do