771f27ac1d08848dcb8e7ac44fd9d4f94b9164d4
[akkoma] / priv / scrubbers / default.ex
1 defmodule Pleroma.HTML.Scrubber.Default do
2 @doc "The default HTML scrubbing policy: no "
3
4 require FastSanitize.Sanitizer.Meta
5 alias FastSanitize.Sanitizer.Meta
6
7 # credo:disable-for-previous-line
8 # No idea how to fix this oneā€¦
9
10 @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], [])
11
12 Meta.strip_comments()
13
14 Meta.allow_tag_with_uri_attributes(:a, ["href", "data-user", "data-tag"], @valid_schemes)
15
16 Meta.allow_tag_with_this_attribute_values(:a, "class", [
17 "hashtag",
18 "u-url",
19 "mention",
20 "u-url mention",
21 "mention u-url"
22 ])
23
24 Meta.allow_tag_with_this_attribute_values(:a, "rel", [
25 "tag",
26 "nofollow",
27 "noopener",
28 "noreferrer",
29 "ugc"
30 ])
31
32 Meta.allow_tag_with_these_attributes(:a, ["name", "title"])
33
34 Meta.allow_tag_with_these_attributes(:abbr, ["title"])
35
36 Meta.allow_tag_with_these_attributes(:b, [])
37 Meta.allow_tag_with_these_attributes(:blockquote, [])
38 Meta.allow_tag_with_these_attributes(:br, [])
39 Meta.allow_tag_with_these_attributes(:code, [])
40 Meta.allow_tag_with_these_attributes(:del, [])
41 Meta.allow_tag_with_these_attributes(:em, [])
42 Meta.allow_tag_with_these_attributes(:hr, [])
43 Meta.allow_tag_with_these_attributes(:i, [])
44 Meta.allow_tag_with_these_attributes(:li, [])
45 Meta.allow_tag_with_these_attributes(:ol, [])
46 Meta.allow_tag_with_these_attributes(:p, [])
47 Meta.allow_tag_with_these_attributes(:pre, [])
48 Meta.allow_tag_with_these_attributes(:strong, [])
49 Meta.allow_tag_with_these_attributes(:sub, [])
50 Meta.allow_tag_with_these_attributes(:sup, [])
51 Meta.allow_tag_with_these_attributes(:ruby, [])
52 Meta.allow_tag_with_these_attributes(:rb, [])
53 Meta.allow_tag_with_these_attributes(:rp, [])
54 Meta.allow_tag_with_these_attributes(:rt, [])
55 Meta.allow_tag_with_these_attributes(:rtc, [])
56 Meta.allow_tag_with_these_attributes(:u, [])
57 Meta.allow_tag_with_these_attributes(:ul, [])
58
59 Meta.allow_tags_with_style_attributes([:span])
60
61 Meta.allow_tag_with_this_attribute_values(:span, "class", [
62 "h-card",
63 "quote-inline",
64 "mfm",
65 "mfm _mfm_tada_",
66 "mfm _mfm_jelly_",
67 "mfm _mfm_twitch_",
68 "mfm _mfm_shake_",
69 "mfm _mfm_spin_",
70 "mfm _mfm_jump_",
71 "mfm _mfm_bounce_",
72 "mfm _mfm_flip_",
73 "mfm _mfm_x2_",
74 "mfm _mfm_x3_",
75 "mfm _mfm_x4_",
76 "mfm _mfm_blur_",
77 "mfm _mfm_rainbow_",
78 "mfm _mfm_rotate_"
79 ])
80
81 Meta.allow_tag_with_these_attributes(:span, [
82 "data-x",
83 "data-y",
84 "data-h",
85 "data-v",
86 "data-left",
87 "data-right"
88 ])
89
90 Meta.allow_tag_with_this_attribute_values(:code, "class", ["inline"])
91
92 @allow_inline_images Pleroma.Config.get([:markup, :allow_inline_images])
93
94 if @allow_inline_images do
95 # restrict img tags to http/https only, because of MediaProxy.
96 Meta.allow_tag_with_uri_attributes(:img, ["src"], ["http", "https"])
97
98 Meta.allow_tag_with_these_attributes(:img, [
99 "width",
100 "height",
101 "title",
102 "alt"
103 ])
104 end
105
106 if Pleroma.Config.get([:markup, :allow_tables]) do
107 Meta.allow_tag_with_these_attributes(:table, [])
108 Meta.allow_tag_with_these_attributes(:tbody, [])
109 Meta.allow_tag_with_these_attributes(:td, [])
110 Meta.allow_tag_with_these_attributes(:th, [])
111 Meta.allow_tag_with_these_attributes(:thead, [])
112 Meta.allow_tag_with_these_attributes(:tr, [])
113 end
114
115 if Pleroma.Config.get([:markup, :allow_headings]) do
116 Meta.allow_tag_with_these_attributes(:h1, [])
117 Meta.allow_tag_with_these_attributes(:h2, [])
118 Meta.allow_tag_with_these_attributes(:h3, [])
119 Meta.allow_tag_with_these_attributes(:h4, [])
120 Meta.allow_tag_with_these_attributes(:h5, [])
121 end
122
123 if Pleroma.Config.get([:markup, :allow_fonts]) do
124 Meta.allow_tag_with_these_attributes(:font, ["face"])
125 end
126
127 Meta.allow_tag_with_these_attributes(:center, [])
128 Meta.allow_tag_with_these_attributes(:small, [])
129
130 Meta.strip_everything_not_covered()
131
132 defp scrub_css(value), do: value
133 end