From 4a178b3d6589bbb9ab08e8a768cc0a3a5d5e9629 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 14 Apr 2018 09:20:18 +0000 Subject: [PATCH] ActivityPub: implement MRF core hook and baseline noop policy object --- config/config.exs | 3 ++- lib/pleroma/web/activity_pub/activity_pub.ex | 6 +++++- lib/pleroma/web/activity_pub/mrf/drop_policy.ex | 8 ++++++++ lib/pleroma/web/activity_pub/mrf/noop_policy.ex | 5 +++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 lib/pleroma/web/activity_pub/mrf/drop_policy.ex create mode 100644 lib/pleroma/web/activity_pub/mrf/noop_policy.ex diff --git a/config/config.exs b/config/config.exs index 68c054457..660ba1775 100644 --- a/config/config.exs +++ b/config/config.exs @@ -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, diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 04b50c1cc..bfb0e04be 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -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 index 000000000..4333bca28 --- /dev/null +++ b/lib/pleroma/web/activity_pub/mrf/drop_policy.ex @@ -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 index 000000000..9dd3acb04 --- /dev/null +++ b/lib/pleroma/web/activity_pub/mrf/noop_policy.ex @@ -0,0 +1,5 @@ +defmodule Pleroma.Web.ActivityPub.MRF.NoOpPolicy do + def filter(object) do + {:ok, object} + end +end