logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

default.ex (4821B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.HTML.Scrubber.Default do
  5. @doc "The default HTML scrubbing policy: no "
  6. require FastSanitize.Sanitizer.Meta
  7. alias FastSanitize.Sanitizer.Meta
  8. # credo:disable-for-previous-line
  9. # No idea how to fix this one…
  10. @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], [])
  11. Meta.strip_comments()
  12. Meta.allow_tag_with_uri_attributes(:a, ["href", "data-user", "data-tag"], @valid_schemes)
  13. Meta.allow_tag_with_this_attribute_values(:a, "class", [
  14. "hashtag",
  15. "u-url",
  16. "mention",
  17. "u-url mention",
  18. "mention u-url",
  19. "mention hashtag"
  20. ])
  21. Meta.allow_tag_with_this_attribute_values(:a, "rel", [
  22. "tag",
  23. "nofollow",
  24. "noopener",
  25. "noreferrer",
  26. "ugc"
  27. ])
  28. Meta.allow_tag_with_these_attributes(:a, ["name", "title", "lang"])
  29. Meta.allow_tag_with_these_attributes(:abbr, ["title", "lang"])
  30. Meta.allow_tag_with_these_attributes(:acronym, ["title", "lang"])
  31. # sort(1)-ed list
  32. Meta.allow_tag_with_these_attributes(:bdi, [])
  33. Meta.allow_tag_with_these_attributes(:bdo, ["dir"])
  34. Meta.allow_tag_with_these_attributes(:big, ["lang"])
  35. Meta.allow_tag_with_these_attributes(:b, ["lang"])
  36. Meta.allow_tag_with_these_attributes(:blockquote, ["lang"])
  37. Meta.allow_tag_with_these_attributes(:br, ["lang"])
  38. Meta.allow_tag_with_these_attributes(:cite, ["lang"])
  39. Meta.allow_tag_with_these_attributes(:code, ["lang"])
  40. Meta.allow_tag_with_these_attributes(:del, ["lang"])
  41. Meta.allow_tag_with_these_attributes(:dfn, ["lang"])
  42. Meta.allow_tag_with_these_attributes(:em, ["lang"])
  43. Meta.allow_tag_with_these_attributes(:hr, ["lang"])
  44. Meta.allow_tag_with_these_attributes(:i, ["lang"])
  45. Meta.allow_tag_with_these_attributes(:ins, ["lang"])
  46. Meta.allow_tag_with_these_attributes(:kbd, ["lang"])
  47. Meta.allow_tag_with_these_attributes(:li, ["lang"])
  48. Meta.allow_tag_with_these_attributes(:ol, ["lang"])
  49. Meta.allow_tag_with_these_attributes(:p, ["lang"])
  50. Meta.allow_tag_with_these_attributes(:pre, ["lang"])
  51. Meta.allow_tag_with_these_attributes(:q, ["lang"])
  52. Meta.allow_tag_with_these_attributes(:rb, ["lang"])
  53. Meta.allow_tag_with_these_attributes(:rp, ["lang"])
  54. Meta.allow_tag_with_these_attributes(:rtc, ["lang"])
  55. Meta.allow_tag_with_these_attributes(:rt, ["lang"])
  56. Meta.allow_tag_with_these_attributes(:ruby, ["lang"])
  57. Meta.allow_tag_with_these_attributes(:samp, ["lang"])
  58. Meta.allow_tag_with_these_attributes(:s, ["lang"])
  59. Meta.allow_tag_with_these_attributes(:small, ["lang"])
  60. Meta.allow_tag_with_these_attributes(:strong, ["lang"])
  61. Meta.allow_tag_with_these_attributes(:sub, ["lang"])
  62. Meta.allow_tag_with_these_attributes(:sup, ["lang"])
  63. Meta.allow_tag_with_these_attributes(:tt, ["lang"])
  64. Meta.allow_tag_with_these_attributes(:u, ["lang"])
  65. Meta.allow_tag_with_these_attributes(:ul, ["lang"])
  66. Meta.allow_tag_with_these_attributes(:var, ["lang"])
  67. Meta.allow_tag_with_these_attributes(:wbr, ["lang"])
  68. Meta.allow_tag_with_this_attribute_values(:span, "class", [
  69. "h-card",
  70. "recipients-inline",
  71. "quote-inline",
  72. "invisible",
  73. "ellipsis"
  74. ])
  75. Meta.allow_tag_with_this_attribute_values(:p, "class", ["quote-inline"])
  76. Meta.allow_tag_with_these_attributes(:span, ["lang"])
  77. Meta.allow_tag_with_this_attribute_values(:code, "class", ["inline"])
  78. @allow_inline_images Pleroma.Config.get([:markup, :allow_inline_images])
  79. if @allow_inline_images do
  80. Meta.allow_tag_with_this_attribute_values(:img, "class", ["emoji"])
  81. # restrict img tags to http/https only, because of MediaProxy.
  82. Meta.allow_tag_with_uri_attributes(:img, ["src"], ["http", "https"])
  83. Meta.allow_tag_with_these_attributes(:img, [
  84. "width",
  85. "height",
  86. "title",
  87. "alt",
  88. "lang"
  89. ])
  90. end
  91. if Pleroma.Config.get([:markup, :allow_tables]) do
  92. Meta.allow_tag_with_these_attributes(:table, ["lang"])
  93. Meta.allow_tag_with_these_attributes(:tbody, ["lang"])
  94. Meta.allow_tag_with_these_attributes(:td, ["lang"])
  95. Meta.allow_tag_with_these_attributes(:th, ["lang"])
  96. Meta.allow_tag_with_these_attributes(:thead, ["lang"])
  97. Meta.allow_tag_with_these_attributes(:tr, ["lang"])
  98. end
  99. if Pleroma.Config.get([:markup, :allow_headings]) do
  100. Meta.allow_tag_with_these_attributes(:h1, ["lang"])
  101. Meta.allow_tag_with_these_attributes(:h2, ["lang"])
  102. Meta.allow_tag_with_these_attributes(:h3, ["lang"])
  103. Meta.allow_tag_with_these_attributes(:h4, ["lang"])
  104. Meta.allow_tag_with_these_attributes(:h5, ["lang"])
  105. end
  106. if Pleroma.Config.get([:markup, :allow_fonts]) do
  107. Meta.allow_tag_with_these_attributes(:font, ["face", "lang"])
  108. end
  109. Meta.strip_everything_not_covered()
  110. end