move to 2.5.5
[anni] / priv / scrubbers / twitter_text.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.HTML.Scrubber.TwitterText do
6   @moduledoc """
7   An HTML scrubbing policy which limits to twitter-style text.  Only
8   paragraphs, breaks and links are allowed through the filter.
9   """
10
11   @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], [])
12
13   require FastSanitize.Sanitizer.Meta
14   alias FastSanitize.Sanitizer.Meta
15
16   Meta.strip_comments()
17
18   # links
19   Meta.allow_tag_with_uri_attributes(:a, ["href", "data-user", "data-tag"], @valid_schemes)
20
21   Meta.allow_tag_with_this_attribute_values(:a, "class", [
22     "hashtag",
23     "u-url",
24     "mention",
25     "u-url mention",
26     "mention u-url"
27   ])
28
29   Meta.allow_tag_with_this_attribute_values(:a, "rel", [
30     "tag",
31     "nofollow",
32     "noopener",
33     "noreferrer"
34   ])
35
36   Meta.allow_tag_with_these_attributes(:a, ["name", "title"])
37
38   # paragraphs and linebreaks
39   Meta.allow_tag_with_these_attributes(:br, [])
40   Meta.allow_tag_with_these_attributes(:p, [])
41
42   # microformats
43   Meta.allow_tag_with_this_attribute_values(:span, "class", ["h-card"])
44   Meta.allow_tag_with_these_attributes(:span, [])
45
46   # allow inline images for custom emoji
47   if Pleroma.Config.get([:markup, :allow_inline_images]) do
48     Meta.allow_tag_with_this_attribute_values(:img, "class", ["emoji"])
49
50     # restrict img tags to http/https only, because of MediaProxy.
51     Meta.allow_tag_with_uri_attributes(:img, ["src"], ["http", "https"])
52
53     Meta.allow_tag_with_these_attributes(:img, [
54       "width",
55       "height",
56       "title",
57       "alt"
58     ])
59   end
60
61   Meta.strip_everything_not_covered()
62 end