html_sanitizer.rb 6.2 KB

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