html: new module providing a configurable markup scrubbing policy
authorWilliam Pitcock <nenolod@dereferenced.org>
Sun, 9 Sep 2018 23:29:00 +0000 (23:29 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Mon, 10 Sep 2018 00:13:57 +0000 (00:13 +0000)
config/config.exs
lib/pleroma/html.ex [new file with mode: 0644]

index ed718c3d3cd6f583a8a7d1a55f53a474abf2f5c5..559a12a91dc0bfeb140c7689acd5722183ffa7eb 100644 (file)
@@ -76,6 +76,9 @@ config :pleroma, :instance,
   quarantined_instances: [],
   managed_config: true
 
+config :pleroma, :markup,
+  scrub_policy: HtmlSanitizeEx.Scrubber.BasicHTML
+
 config :pleroma, :fe,
   theme: "pleroma-dark",
   logo: "/static/logo.png",
diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex
new file mode 100644 (file)
index 0000000..0ec73a9
--- /dev/null
@@ -0,0 +1,14 @@
+defmodule Pleroma.HTML do
+  alias HtmlSanitizeEx.Scrubber
+
+  @markup Application.get_env(:pleroma, :markup)
+
+  def filter_tags(html) do
+    scrubber = Keyword.get(@markup, :scrub_policy)
+    html |> Scrubber.scrub(scrubber)
+  end
+
+  def strip_tags(html) do
+    html |> Scrubber.scrub(Scrubber.StripTags)
+  end
+end