mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-24 09:00:29 +00:00
Merge branch 'feature/mrf-scrub' into 'develop'
MRF: html scrubbing filter See merge request pleroma/pleroma!345
This commit is contained in:
commit
2881275291
3 changed files with 32 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -3,9 +3,13 @@ defmodule Pleroma.HTML do
|
|||
|
||||
@markup Application.get_env(:pleroma, :markup)
|
||||
|
||||
def filter_tags(html, scrubber) do
|
||||
html |> Scrubber.scrub(scrubber)
|
||||
end
|
||||
|
||||
def filter_tags(html) do
|
||||
scrubber = Keyword.get(@markup, :scrub_policy)
|
||||
html |> Scrubber.scrub(scrubber)
|
||||
filter_tags(html, scrubber)
|
||||
end
|
||||
|
||||
def strip_tags(html) do
|
||||
|
|
25
lib/pleroma/web/activity_pub/mrf/normalize_markup.ex
Normal file
25
lib/pleroma/web/activity_pub/mrf/normalize_markup.ex
Normal file
|
@ -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
|
Loading…
Reference in a new issue