move to 2.5.5
[anni] / lib / pleroma / web / activity_pub / mrf / normalize_markup.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkup do
6   @moduledoc "Scrub configured hypertext markup"
7   alias Pleroma.HTML
8
9   @behaviour Pleroma.Web.ActivityPub.MRF.Policy
10
11   @impl true
12   def history_awareness, do: :auto
13
14   @impl true
15   def filter(%{"type" => type, "object" => child_object} = object)
16       when type in ["Create", "Update"] do
17     scrub_policy = Pleroma.Config.get([:mrf_normalize_markup, :scrub_policy])
18
19     content =
20       child_object["content"]
21       |> HTML.filter_tags(scrub_policy)
22
23     object = put_in(object, ["object", "content"], content)
24
25     {:ok, object}
26   end
27
28   def filter(object), do: {:ok, object}
29
30   @impl true
31   def describe, do: {:ok, %{}}
32
33   @impl true
34   def config_description do
35     %{
36       key: :mrf_normalize_markup,
37       related_policy: "Pleroma.Web.ActivityPub.MRF.NormalizeMarkup",
38       label: "MRF Normalize Markup",
39       description: "MRF NormalizeMarkup settings. Scrub configured hypertext markup.",
40       children: [
41         %{
42           key: :scrub_policy,
43           type: :module,
44           suggestions: [Pleroma.HTML.Scrubber.Default]
45         }
46       ]
47     }
48   end
49 end