MRF: add policy for normalizing HTML markup (local and remote) to a specific policy
authorWilliam Pitcock <nenolod@dereferenced.org>
Mon, 10 Sep 2018 00:48:28 +0000 (00:48 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Sun, 16 Sep 2018 01:25:36 +0000 (01:25 +0000)
config/config.exs
lib/pleroma/web/activity_pub/mrf/normalize_markup.ex [new file with mode: 0644]

index d5c5b7902e1534c0e0a29979462c9fbf67f930b8..d8edc4862bb0ec7e1843afa38a4b375edeb7af51 100644 (file)
@@ -104,6 +104,8 @@ config :pleroma, :activitypub,
 
 config :pleroma, :user, deny_follow_blocked: true
 
+config :pleroma, :mrf_normalize_markup, scrub_policy: Pleroma.HTML.Scrubber.Default
+
 config :pleroma, :mrf_rejectnonpublic,
   allow_followersonly: false,
   allow_direct: false
diff --git a/lib/pleroma/web/activity_pub/mrf/normalize_markup.ex b/lib/pleroma/web/activity_pub/mrf/normalize_markup.ex
new file mode 100644 (file)
index 0000000..b4f91f3
--- /dev/null
@@ -0,0 +1,25 @@
+defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkup do
+  alias Pleroma.HTML
+
+  @behaviour Pleroma.Web.ActivityPub.MRF
+
+  @mrf_normalize_markup Application.get_env(:pleroma, :mrf_normalize_markup)
+
+  def filter(%{"type" => activity_type} = object) when activity_type == "Create" do
+    scrub_policy = Keyword.get(@mrf_normalize_markup, :scrub_policy)
+
+    child = object["object"]
+
+    content =
+      child["content"]
+      |> HTML.filter_tags(scrub_policy)
+
+    child = Map.put(child, "content", content)
+
+    object = Map.put(object, "object", child)
+
+    {:ok, object}
+  end
+
+  def filter(object), do: {:ok, object}
+end