Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.9KB

  1. defmodule Pleroma.HTML.Scrubber.Default do
  2. @doc "The default HTML scrubbing policy: no "
  3. require FastSanitize.Sanitizer.Meta
  4. alias FastSanitize.Sanitizer.Meta
  5. # credo:disable-for-previous-line
  6. # No idea how to fix this one…
  7. @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], [])
  8. Meta.strip_comments()
  9. Meta.allow_tag_with_uri_attributes(:a, ["href", "data-user", "data-tag"], @valid_schemes)
  10. Meta.allow_tag_with_this_attribute_values(:a, "class", [
  11. "hashtag",
  12. "u-url",
  13. "mention",
  14. "u-url mention",
  15. "mention u-url"
  16. ])
  17. Meta.allow_tag_with_this_attribute_values(:a, "rel", [
  18. "tag",
  19. "nofollow",
  20. "noopener",
  21. "noreferrer",
  22. "ugc"
  23. ])
  24. Meta.allow_tag_with_these_attributes(:a, ["name", "title"])
  25. Meta.allow_tag_with_these_attributes(:abbr, ["title"])
  26. Meta.allow_tag_with_these_attributes(:b, [])
  27. Meta.allow_tag_with_these_attributes(:blockquote, [])
  28. Meta.allow_tag_with_these_attributes(:br, [])
  29. Meta.allow_tag_with_these_attributes(:code, [])
  30. Meta.allow_tag_with_these_attributes(:del, [])
  31. Meta.allow_tag_with_these_attributes(:em, [])
  32. Meta.allow_tag_with_these_attributes(:i, [])
  33. Meta.allow_tag_with_these_attributes(:li, [])
  34. Meta.allow_tag_with_these_attributes(:ol, [])
  35. Meta.allow_tag_with_these_attributes(:p, [])
  36. Meta.allow_tag_with_these_attributes(:pre, [])
  37. Meta.allow_tag_with_these_attributes(:strong, [])
  38. Meta.allow_tag_with_these_attributes(:sub, [])
  39. Meta.allow_tag_with_these_attributes(:sup, [])
  40. Meta.allow_tag_with_these_attributes(:u, [])
  41. Meta.allow_tag_with_these_attributes(:ul, [])
  42. Meta.allow_tag_with_this_attribute_values(:span, "class", ["h-card"])
  43. Meta.allow_tag_with_these_attributes(:span, [])
  44. @allow_inline_images Pleroma.Config.get([:markup, :allow_inline_images])
  45. if @allow_inline_images do
  46. # restrict img tags to http/https only, because of MediaProxy.
  47. Meta.allow_tag_with_uri_attributes(:img, ["src"], ["http", "https"])
  48. Meta.allow_tag_with_these_attributes(:img, [
  49. "width",
  50. "height",
  51. "class",
  52. "title",
  53. "alt"
  54. ])
  55. end
  56. if Pleroma.Config.get([:markup, :allow_tables]) do
  57. Meta.allow_tag_with_these_attributes(:table, [])
  58. Meta.allow_tag_with_these_attributes(:tbody, [])
  59. Meta.allow_tag_with_these_attributes(:td, [])
  60. Meta.allow_tag_with_these_attributes(:th, [])
  61. Meta.allow_tag_with_these_attributes(:thead, [])
  62. Meta.allow_tag_with_these_attributes(:tr, [])
  63. end
  64. if Pleroma.Config.get([:markup, :allow_headings]) do
  65. Meta.allow_tag_with_these_attributes(:h1, [])
  66. Meta.allow_tag_with_these_attributes(:h2, [])
  67. Meta.allow_tag_with_these_attributes(:h3, [])
  68. Meta.allow_tag_with_these_attributes(:h4, [])
  69. Meta.allow_tag_with_these_attributes(:h5, [])
  70. end
  71. if Pleroma.Config.get([:markup, :allow_fonts]) do
  72. Meta.allow_tag_with_these_attributes(:font, ["face"])
  73. end
  74. Meta.strip_everything_not_covered()
  75. end