html_sanitizer.rb 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # content of this tags will also be removed
  3. Rails.application.config.html_sanitizer_tags_remove_content = %w[
  4. style
  5. comment
  6. meta
  7. script
  8. title
  9. ]
  10. # content of this tags will will be inserted html quoted
  11. Rails.application.config.html_sanitizer_tags_quote_content = %w[]
  12. # only this tags are allowed
  13. Rails.application.config.html_sanitizer_tags_allowlist = %w[
  14. a abbr acronym address area article aside audio
  15. b bdi bdo big blockquote br
  16. canvas caption center cite code col colgroup command
  17. datalist dd del details dfn dir div dl dt em
  18. figcaption figure footer h1 h2 h3 h4 h5 h6 header hr
  19. i img ins kbd label legend li map mark menu meter nav
  20. ol output optgroup option p pre q
  21. s samp section small span strike strong sub summary sup
  22. text table tbody td tfoot th thead time tr tt u ul var video
  23. ]
  24. # attributes allowed for tags
  25. Rails.application.config.html_sanitizer_attributes_allowlist = {
  26. :all => %w[class dir lang title translate data-signature data-signature-id],
  27. 'a' => %w[href hreflang name rel data-target-id data-target-type data-mention-user-id],
  28. 'abbr' => %w[title],
  29. 'blockquote' => %w[type cite],
  30. 'col' => %w[span width],
  31. 'colgroup' => %w[span width],
  32. 'data' => %w[value],
  33. 'del' => %w[cite datetime],
  34. 'dfn' => %w[title],
  35. 'img' => %w[align alt border height src srcset width style],
  36. 'ins' => %w[cite datetime],
  37. 'li' => %w[value],
  38. 'ol' => %w[reversed start type],
  39. 'table' => %w[align bgcolor border cellpadding cellspacing frame rules sortable summary width style],
  40. 'td' => %w[abbr align axis colspan headers rowspan valign width style],
  41. 'th' => %w[abbr align axis colspan headers rowspan scope sorted valign width style],
  42. 'tr' => %w[width style],
  43. 'ul' => %w[type],
  44. 'q' => %w[cite],
  45. 'span' => %w[style],
  46. 'div' => %w[style],
  47. 'p' => %w[style],
  48. 'time' => %w[datetime pubdate],
  49. }
  50. # only this css properties are allowed
  51. Rails.application.config.html_sanitizer_css_properties_allowlist = {
  52. 'img' => %w[
  53. width height
  54. max-width min-width
  55. max-height min-height
  56. ],
  57. 'span' => %w[
  58. color
  59. background background-color
  60. ],
  61. 'div' => %w[
  62. color
  63. ],
  64. 'p' => %w[
  65. white-space
  66. ],
  67. 'table' => %w[
  68. background background-color color font-size vertical-align
  69. margin margin-top margin-right margin-bottom margin-left
  70. padding padding-top padding-right padding-bottom padding-left
  71. text-align
  72. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  73. border-top-width border-right-width border-bottom-width border-left-width
  74. border-top-color border-right-color border-bottom-color border-left-color
  75. border-top-style border-right-style border-bottom-style border-left-style
  76. width
  77. ],
  78. 'th' => %w[
  79. background background-color color font-size vertical-align
  80. margin margin-top margin-right margin-bottom margin-left
  81. padding padding-top padding-right padding-bottom padding-left
  82. text-align
  83. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  84. border-top-width border-right-width border-bottom-width border-left-width
  85. border-top-color border-right-color border-bottom-color border-left-color
  86. border-top-style border-right-style border-bottom-style border-left-style
  87. width
  88. ],
  89. 'tr' => %w[
  90. background background-color color font-size vertical-align
  91. margin margin-top margin-right margin-bottom margin-left
  92. padding padding-top padding-right padding-bottom padding-left
  93. text-align
  94. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  95. border-top-width border-right-width border-bottom-width border-left-width
  96. border-top-color border-right-color border-bottom-color border-left-color
  97. border-top-style border-right-style border-bottom-style border-left-style
  98. width
  99. ],
  100. 'td' => %w[
  101. background background-color color font-size vertical-align
  102. margin margin-top margin-right margin-bottom margin-left
  103. padding padding-top padding-right padding-bottom padding-left
  104. text-align
  105. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  106. border-top-width border-right-width border-bottom-width border-left-width
  107. border-top-color border-right-color border-bottom-color border-left-color
  108. border-top-style border-right-style border-bottom-style border-left-style
  109. width
  110. ],
  111. }
  112. Rails.application.config.html_sanitizer_css_values_blocklist = {
  113. 'div' => [
  114. 'color:white',
  115. 'color:black',
  116. 'color:#000',
  117. 'color:#000000',
  118. 'color:#fff',
  119. 'color:#ffffff',
  120. 'color:rgb(0,0,0)',
  121. ],
  122. 'span' => [
  123. 'color:white',
  124. 'color:black',
  125. 'color:#000',
  126. 'color:#000000',
  127. 'color:#fff',
  128. 'color:#ffffff',
  129. 'color:rgb(0,0,0)',
  130. ],
  131. 'p' => [
  132. 'white-space:nowrap',
  133. 'white-space:pre',
  134. ],
  135. 'table' => [
  136. 'font-size:0',
  137. 'font-size:0px',
  138. 'font-size:0pt',
  139. 'font-size:0em',
  140. 'font-size:0%',
  141. 'font-size:1',
  142. 'font-size:1px',
  143. 'font-size:1pt',
  144. 'font-size:1em',
  145. 'font-size:1%',
  146. 'font-size:2',
  147. 'font-size:2px',
  148. 'font-size:2pt',
  149. 'font-size:2em',
  150. 'font-size:2%',
  151. 'font-size:3',
  152. 'font-size:3px',
  153. 'font-size:3pt',
  154. 'font-size:3em',
  155. 'font-size:3%',
  156. 'display:none',
  157. 'visibility:hidden',
  158. 'width:0',
  159. 'width:0px',
  160. 'width:0pt',
  161. 'width:0em',
  162. 'width:0cm',
  163. 'width:0%',
  164. ],
  165. 'th' => [
  166. 'font-size:0',
  167. 'font-size:0px',
  168. 'font-size:0pt',
  169. 'font-size:0em',
  170. 'font-size:0%',
  171. 'font-size:1',
  172. 'font-size:1px',
  173. 'font-size:1pt',
  174. 'font-size:1em',
  175. 'font-size:1%',
  176. 'font-size:2',
  177. 'font-size:2px',
  178. 'font-size:2pt',
  179. 'font-size:2em',
  180. 'font-size:2%',
  181. 'font-size:3',
  182. 'font-size:3px',
  183. 'font-size:3pt',
  184. 'font-size:3em',
  185. 'font-size:3%',
  186. 'display:none',
  187. 'visibility:hidden',
  188. 'width:0',
  189. 'width:0px',
  190. 'width:0pt',
  191. 'width:0em',
  192. 'width:0cm',
  193. 'width:0%',
  194. ],
  195. 'tr' => [
  196. 'font-size:0',
  197. 'font-size:0px',
  198. 'font-size:0pt',
  199. 'font-size:0em',
  200. 'font-size:0%',
  201. 'font-size:1',
  202. 'font-size:1px',
  203. 'font-size:1pt',
  204. 'font-size:1em',
  205. 'font-size:1%',
  206. 'font-size:2',
  207. 'font-size:2px',
  208. 'font-size:2pt',
  209. 'font-size:2em',
  210. 'font-size:2%',
  211. 'font-size:3',
  212. 'font-size:3px',
  213. 'font-size:3pt',
  214. 'font-size:3em',
  215. 'font-size:3%',
  216. 'display:none',
  217. 'visibility:hidden',
  218. 'width:0',
  219. 'width:0px',
  220. 'width:0pt',
  221. 'width:0em',
  222. 'width:0cm',
  223. 'width:0%',
  224. ],
  225. 'td' => [
  226. 'font-size:0',
  227. 'font-size:0px',
  228. 'font-size:0pt',
  229. 'font-size:0em',
  230. 'font-size:0%',
  231. 'font-size:1',
  232. 'font-size:1px',
  233. 'font-size:1pt',
  234. 'font-size:1em',
  235. 'font-size:1%',
  236. 'font-size:2',
  237. 'font-size:2px',
  238. 'font-size:2pt',
  239. 'font-size:2em',
  240. 'font-size:2%',
  241. 'font-size:3',
  242. 'font-size:3px',
  243. 'font-size:3pt',
  244. 'font-size:3em',
  245. 'font-size:3%',
  246. 'display:none',
  247. 'visibility:hidden',
  248. 'width:0',
  249. 'width:0px',
  250. 'width:0pt',
  251. 'width:0em',
  252. 'width:0cm',
  253. 'width:0%',
  254. ],
  255. }