html_sanitizer.rb 7.3 KB

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