ActivityPub: implement MRF core hook and baseline noop policy object
authorWilliam Pitcock <nenolod@dereferenced.org>
Sat, 14 Apr 2018 09:20:18 +0000 (09:20 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Sat, 14 Apr 2018 11:32:44 +0000 (06:32 -0500)
config/config.exs
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/mrf/drop_policy.ex [new file with mode: 0644]
lib/pleroma/web/activity_pub/mrf/noop_policy.ex [new file with mode: 0644]

index 68c0544579803bc96249bd71f325bb944a73f0f0..660ba17755413cb21ff5c3dcf5a572cd80b95308 100644 (file)
@@ -52,7 +52,8 @@ config :pleroma, :instance,
   limit: 5000,
   upload_limit: 16_000_000,
   registrations_open: true,
-  federating: true
+  federating: true,
+  rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy
 
 config :pleroma, :media_proxy,
   enabled: false,
index 04b50c1cc0fc32870dad268d569648c6e8d60263..bfb0e04be137382bbe90893eec063671914969ce 100644 (file)
@@ -10,6 +10,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
   @httpoison Application.get_env(:pleroma, :httpoison)
 
+  @instance Application.get_env(:pleroma, :instance)
+  @rewrite_policy Keyword.get(@instance, :rewrite_policy)
+
   def get_recipients(data) do
     (data["to"] || []) ++ (data["cc"] || [])
   end
@@ -17,7 +20,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   def insert(map, local \\ true) when is_map(map) do
     with nil <- Activity.get_by_ap_id(map["id"]),
          map <- lazy_put_activity_defaults(map),
-         :ok <- insert_full_object(map) do
+         :ok <- insert_full_object(map),
+         {:ok, map} <- @rewrite_policy.filter(map) do
       {:ok, activity} =
         Repo.insert(%Activity{
           data: map,
diff --git a/lib/pleroma/web/activity_pub/mrf/drop_policy.ex b/lib/pleroma/web/activity_pub/mrf/drop_policy.ex
new file mode 100644 (file)
index 0000000..4333bca
--- /dev/null
@@ -0,0 +1,8 @@
+defmodule Pleroma.Web.ActivityPub.MRF.DropPolicy do
+  require Logger
+
+  def filter(object) do
+    Logger.info("REJECTING #{inspect(object)}")
+    {:reject, object}
+  end
+end
diff --git a/lib/pleroma/web/activity_pub/mrf/noop_policy.ex b/lib/pleroma/web/activity_pub/mrf/noop_policy.ex
new file mode 100644 (file)
index 0000000..9dd3acb
--- /dev/null
@@ -0,0 +1,5 @@
+defmodule Pleroma.Web.ActivityPub.MRF.NoOpPolicy do
+  def filter(object) do
+    {:ok, object}
+  end
+end