html_sanitizer.rb 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. # content of this tags will also be removed
  2. Rails.application.config.html_sanitizer_tags_remove_content = %w[
  3. style
  4. comment
  5. meta
  6. ]
  7. # content of this tags will will be inserted html quoted
  8. Rails.application.config.html_sanitizer_tags_quote_content = %w[
  9. script
  10. ]
  11. # only this tags are allowed
  12. Rails.application.config.html_sanitizer_tags_whitelist = %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_whitelist = {
  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. 'time' => %w[datetime pubdate],
  47. }
  48. # only this css properties are allowed
  49. Rails.application.config.html_sanitizer_css_properties_whitelist = {
  50. 'img' => %w[
  51. width height
  52. max-width min-width
  53. max-height min-height
  54. ],
  55. 'span' => %w[
  56. color
  57. ],
  58. 'div' => %w[
  59. color
  60. ],
  61. 'table' => %w[
  62. background background-color color font-size vertical-align
  63. margin margin-top margin-right margin-bottom margin-left
  64. padding padding-top padding-right padding-bottom padding-left
  65. text-align
  66. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  67. border-top-width border-right-width border-bottom-width border-left-width
  68. border-top-color border-right-color border-bottom-color border-left-color
  69. border-top-style border-right-style border-bottom-style border-left-style
  70. ],
  71. 'th' => %w[
  72. background background-color color font-size vertical-align
  73. margin margin-top margin-right margin-bottom margin-left
  74. padding padding-top padding-right padding-bottom padding-left
  75. text-align
  76. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  77. border-top-width border-right-width border-bottom-width border-left-width
  78. border-top-color border-right-color border-bottom-color border-left-color
  79. border-top-style border-right-style border-bottom-style border-left-style
  80. ],
  81. 'tr' => %w[
  82. background background-color color font-size vertical-align
  83. margin margin-top margin-right margin-bottom margin-left
  84. padding padding-top padding-right padding-bottom padding-left
  85. text-align
  86. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  87. border-top-width border-right-width border-bottom-width border-left-width
  88. border-top-color border-right-color border-bottom-color border-left-color
  89. border-top-style border-right-style border-bottom-style border-left-style
  90. ],
  91. 'td' => %w[
  92. background background-color color font-size vertical-align
  93. margin margin-top margin-right margin-bottom margin-left
  94. padding padding-top padding-right padding-bottom padding-left
  95. text-align
  96. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  97. border-top-width border-right-width border-bottom-width border-left-width
  98. border-top-color border-right-color border-bottom-color border-left-color
  99. border-top-style border-right-style border-bottom-style border-left-style
  100. ],
  101. }
  102. Rails.application.config.html_sanitizer_css_values_backlist = {
  103. 'div' => [
  104. 'color:white',
  105. 'color:black',
  106. 'color:#000',
  107. 'color:#000000',
  108. 'color:#fff',
  109. 'color:#ffffff',
  110. 'color:rgb(0,0,0)',
  111. ],
  112. 'span' => [
  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. 'table' => [
  122. 'font-size:0',
  123. 'font-size:0px',
  124. 'font-size:0em',
  125. 'font-size:0%',
  126. 'font-size:1px',
  127. 'font-size:1em',
  128. 'font-size:1%',
  129. 'font-size:2',
  130. 'font-size:2px',
  131. 'font-size:2em',
  132. 'font-size:2%',
  133. 'font-size:3',
  134. 'font-size:3px',
  135. 'font-size:3em',
  136. 'font-size:3%',
  137. 'display:none',
  138. 'visibility:hidden',
  139. ],
  140. 'th' => [
  141. 'font-size:0',
  142. 'font-size:0px',
  143. 'font-size:0em',
  144. 'font-size:0%',
  145. 'font-size:1px',
  146. 'font-size:1em',
  147. 'font-size:1%',
  148. 'font-size:2',
  149. 'font-size:2px',
  150. 'font-size:2em',
  151. 'font-size:2%',
  152. 'font-size:3',
  153. 'font-size:3px',
  154. 'font-size:3em',
  155. 'font-size:3%',
  156. 'display:none',
  157. 'visibility:hidden',
  158. ],
  159. 'tr' => [
  160. 'font-size:0',
  161. 'font-size:0px',
  162. 'font-size:0em',
  163. 'font-size:0%',
  164. 'font-size:1',
  165. 'font-size:1px',
  166. 'font-size:1em',
  167. 'font-size:1%',
  168. 'font-size:2',
  169. 'font-size:2px',
  170. 'font-size:2em',
  171. 'font-size:2%',
  172. 'font-size:3',
  173. 'font-size:3px',
  174. 'font-size:3em',
  175. 'font-size:3%',
  176. 'display:none',
  177. 'visibility:hidden',
  178. ],
  179. 'td' => [
  180. 'font-size:0',
  181. 'font-size:0px',
  182. 'font-size:0em',
  183. 'font-size:0%',
  184. 'font-size:1px',
  185. 'font-size:1em',
  186. 'font-size:1%',
  187. 'font-size:2',
  188. 'font-size:2px',
  189. 'font-size:2em',
  190. 'font-size:2%',
  191. 'font-size:3',
  192. 'font-size:3px',
  193. 'font-size:3em',
  194. 'font-size:3%',
  195. 'display:none',
  196. 'visibility:hidden',
  197. ],
  198. }