html_sanitizer.rb 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. # Copyright (C) 2012-2022 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. ]
  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. '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. ],
  59. 'div' => %w[
  60. color
  61. ],
  62. 'table' => %w[
  63. background background-color color font-size vertical-align
  64. margin margin-top margin-right margin-bottom margin-left
  65. padding padding-top padding-right padding-bottom padding-left
  66. text-align
  67. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  68. border-top-width border-right-width border-bottom-width border-left-width
  69. border-top-color border-right-color border-bottom-color border-left-color
  70. border-top-style border-right-style border-bottom-style border-left-style
  71. ],
  72. 'th' => %w[
  73. background background-color color font-size vertical-align
  74. margin margin-top margin-right margin-bottom margin-left
  75. padding padding-top padding-right padding-bottom padding-left
  76. text-align
  77. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  78. border-top-width border-right-width border-bottom-width border-left-width
  79. border-top-color border-right-color border-bottom-color border-left-color
  80. border-top-style border-right-style border-bottom-style border-left-style
  81. ],
  82. 'tr' => %w[
  83. background background-color color font-size vertical-align
  84. margin margin-top margin-right margin-bottom margin-left
  85. padding padding-top padding-right padding-bottom padding-left
  86. text-align
  87. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  88. border-top-width border-right-width border-bottom-width border-left-width
  89. border-top-color border-right-color border-bottom-color border-left-color
  90. border-top-style border-right-style border-bottom-style border-left-style
  91. ],
  92. 'td' => %w[
  93. background background-color color font-size vertical-align
  94. margin margin-top margin-right margin-bottom margin-left
  95. padding padding-top padding-right padding-bottom padding-left
  96. text-align
  97. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  98. border-top-width border-right-width border-bottom-width border-left-width
  99. border-top-color border-right-color border-bottom-color border-left-color
  100. border-top-style border-right-style border-bottom-style border-left-style
  101. ],
  102. }
  103. Rails.application.config.html_sanitizer_css_values_blocklist = {
  104. 'div' => [
  105. 'color:white',
  106. 'color:black',
  107. 'color:#000',
  108. 'color:#000000',
  109. 'color:#fff',
  110. 'color:#ffffff',
  111. 'color:rgb(0,0,0)',
  112. ],
  113. 'span' => [
  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. 'table' => [
  123. 'font-size:0',
  124. 'font-size:0px',
  125. 'font-size:0pt',
  126. 'font-size:0em',
  127. 'font-size:0%',
  128. 'font-size:1',
  129. 'font-size:1px',
  130. 'font-size:1pt',
  131. 'font-size:1em',
  132. 'font-size:1%',
  133. 'font-size:2',
  134. 'font-size:2px',
  135. 'font-size:2pt',
  136. 'font-size:2em',
  137. 'font-size:2%',
  138. 'font-size:3',
  139. 'font-size:3px',
  140. 'font-size:3pt',
  141. 'font-size:3em',
  142. 'font-size:3%',
  143. 'display:none',
  144. 'visibility:hidden',
  145. ],
  146. 'th' => [
  147. 'font-size:0',
  148. 'font-size:0px',
  149. 'font-size:0pt',
  150. 'font-size:0em',
  151. 'font-size:0%',
  152. 'font-size:1',
  153. 'font-size:1px',
  154. 'font-size:1pt',
  155. 'font-size:1em',
  156. 'font-size:1%',
  157. 'font-size:2',
  158. 'font-size:2px',
  159. 'font-size:2pt',
  160. 'font-size:2em',
  161. 'font-size:2%',
  162. 'font-size:3',
  163. 'font-size:3px',
  164. 'font-size:3pt',
  165. 'font-size:3em',
  166. 'font-size:3%',
  167. 'display:none',
  168. 'visibility:hidden',
  169. ],
  170. 'tr' => [
  171. 'font-size:0',
  172. 'font-size:0px',
  173. 'font-size:0pt',
  174. 'font-size:0em',
  175. 'font-size:0%',
  176. 'font-size:1',
  177. 'font-size:1px',
  178. 'font-size:1pt',
  179. 'font-size:1em',
  180. 'font-size:1%',
  181. 'font-size:2',
  182. 'font-size:2px',
  183. 'font-size:2pt',
  184. 'font-size:2em',
  185. 'font-size:2%',
  186. 'font-size:3',
  187. 'font-size:3px',
  188. 'font-size:3pt',
  189. 'font-size:3em',
  190. 'font-size:3%',
  191. 'display:none',
  192. 'visibility:hidden',
  193. ],
  194. 'td' => [
  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. ],
  218. }