html_sanitizer.rb 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # content of this tags will also be removed
  2. Rails.application.config.html_sanitizer_tags_remove_content = %w[
  3. style
  4. ]
  5. # content of this tags will will be inserted html quoted
  6. Rails.application.config.html_sanitizer_tags_quote_content = %w[
  7. script
  8. ]
  9. # only this tags are allowed
  10. Rails.application.config.html_sanitizer_tags_whitelist = %w[
  11. a abbr acronym address area article aside audio
  12. b bdi bdo big blockquote br
  13. canvas caption center cite code col colgroup command
  14. datalist dd del details dfn dir div dl dt em
  15. figcaption figure footer h1 h2 h3 h4 h5 h6 header hr
  16. i img ins kbd label legend li map mark menu meter nav
  17. ol output optgroup option p pre q
  18. s samp section small span strike strong sub summary sup
  19. text table tbody td tfoot th thead time tr tt u ul var video
  20. ]
  21. # attributes allowed for tags
  22. Rails.application.config.html_sanitizer_attributes_whitelist = {
  23. :all => %w[class dir lang title translate data-signature data-signature-id],
  24. 'a' => %w[href hreflang name rel],
  25. 'abbr' => %w[title],
  26. 'blockquote' => %w[type cite],
  27. 'col' => %w[span width],
  28. 'colgroup' => %w[span width],
  29. 'data' => %w[value],
  30. 'del' => %w[cite datetime],
  31. 'dfn' => %w[title],
  32. 'img' => %w[align alt border height src srcset width style],
  33. 'ins' => %w[cite datetime],
  34. 'li' => %w[value],
  35. 'ol' => %w[reversed start type],
  36. 'table' => %w[align bgcolor border cellpadding cellspacing frame rules sortable summary width style],
  37. 'td' => %w[abbr align axis colspan headers rowspan valign width style],
  38. 'th' => %w[abbr align axis colspan headers rowspan scope sorted valign width style],
  39. 'tr' => %w[width style],
  40. 'ul' => %w[type],
  41. 'q' => %w[cite],
  42. 'span' => %w[style],
  43. 'time' => %w[datetime pubdate],
  44. }
  45. # only this css properties are allowed
  46. Rails.application.config.html_sanitizer_css_properties_whitelist = {
  47. 'img' => %w[
  48. width height
  49. max-width min-width
  50. max-height min-height
  51. ],
  52. 'span' => %w[
  53. color
  54. ],
  55. 'table' => %w[
  56. background background-color color font-size vertical-align
  57. margin margin-top margin-right margin-bottom margin-left
  58. padding padding-top padding-right padding-bottom padding-left
  59. text-align
  60. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  61. border-top-width
  62. border-right-width
  63. border-bottom-width
  64. border-left-width
  65. border-top-color
  66. border-right-color
  67. border-bottom-color
  68. border-left-color
  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
  77. border-right-width
  78. border-bottom-width
  79. border-left-width
  80. border-top-color
  81. border-right-color
  82. border-bottom-color
  83. border-left-color
  84. ],
  85. 'tr' => %w[
  86. background background-color color font-size vertical-align
  87. margin margin-top margin-right margin-bottom margin-left
  88. padding padding-top padding-right padding-bottom padding-left
  89. text-align
  90. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  91. border-top-width
  92. border-right-width
  93. border-bottom-width
  94. border-left-width
  95. border-top-color
  96. border-right-color
  97. border-bottom-color
  98. border-left-color
  99. ],
  100. 'td' => %w[
  101. background background-color color font-size vertical-align
  102. margin margin-top margin-right margin-bottom margin-left
  103. padding padding-top padding-right padding-bottom padding-left
  104. text-align
  105. border border-top border-right border-bottom border-left border-collapse border-style border-spacing
  106. border-top-width
  107. border-right-width
  108. border-bottom-width
  109. border-left-width
  110. border-top-color
  111. border-right-color
  112. border-bottom-color
  113. border-left-color
  114. ],
  115. }