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