html_sanitizer.rb 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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],
  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. '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. 'table' => %w[
  58. background background-color color font-size vertical-align
  59. margin margin-top margin-right margin-bottom margin-left
  60. padding padding-top padding-right padding-bottom padding-left
  61. text-align
  62. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  63. border-top-width border-right-width border-bottom-width border-left-width
  64. border-top-color border-right-color border-bottom-color border-left-color
  65. border-top-style border-right-style border-bottom-style border-left-style
  66. ],
  67. 'th' => %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. ],
  77. 'tr' => %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. ],
  87. 'td' => %w[
  88. background background-color color font-size vertical-align
  89. margin margin-top margin-right margin-bottom margin-left
  90. padding padding-top padding-right padding-bottom padding-left
  91. text-align
  92. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  93. border-top-width border-right-width border-bottom-width border-left-width
  94. border-top-color border-right-color border-bottom-color border-left-color
  95. border-top-style border-right-style border-bottom-style border-left-style
  96. ],
  97. }
  98. Rails.application.config.html_sanitizer_css_values_backlist = {
  99. 'table' => [
  100. 'font-size:0',
  101. 'font-size:0px',
  102. 'font-size:0em',
  103. 'font-size:0%',
  104. 'display:none',
  105. 'visibility:hidden',
  106. ],
  107. 'th' => [
  108. 'font-size:0',
  109. 'font-size:0px',
  110. 'font-size:0em',
  111. 'font-size:0%',
  112. 'display:none',
  113. 'visibility:hidden',
  114. ],
  115. 'tr' => [
  116. 'font-size:0',
  117. 'font-size:0px',
  118. 'font-size:0em',
  119. 'font-size:0%',
  120. 'display:none',
  121. 'visibility:hidden',
  122. ],
  123. 'td' => [
  124. 'font-size:0',
  125. 'font-size:0px',
  126. 'font-size:0em',
  127. 'font-size:0%',
  128. 'display:none',
  129. 'visibility:hidden',
  130. ],
  131. }