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.

58 lines
1.5KB

  1. defmodule Pleroma.HTML.Scrubber.TwitterText do
  2. @moduledoc """
  3. An HTML scrubbing policy which limits to twitter-style text. Only
  4. paragraphs, breaks and links are allowed through the filter.
  5. """
  6. @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], [])
  7. require FastSanitize.Sanitizer.Meta
  8. alias FastSanitize.Sanitizer.Meta
  9. Meta.strip_comments()
  10. # links
  11. Meta.allow_tag_with_uri_attributes(:a, ["href", "data-user", "data-tag"], @valid_schemes)
  12. Meta.allow_tag_with_this_attribute_values(:a, "class", [
  13. "hashtag",
  14. "u-url",
  15. "mention",
  16. "u-url mention",
  17. "mention u-url"
  18. ])
  19. Meta.allow_tag_with_this_attribute_values(:a, "rel", [
  20. "tag",
  21. "nofollow",
  22. "noopener",
  23. "noreferrer"
  24. ])
  25. Meta.allow_tag_with_these_attributes(:a, ["name", "title"])
  26. # paragraphs and linebreaks
  27. Meta.allow_tag_with_these_attributes(:br, [])
  28. Meta.allow_tag_with_these_attributes(:p, [])
  29. # microformats
  30. Meta.allow_tag_with_this_attribute_values(:span, "class", ["h-card"])
  31. Meta.allow_tag_with_these_attributes(:span, [])
  32. # allow inline images for custom emoji
  33. if Pleroma.Config.get([:markup, :allow_inline_images]) do
  34. # restrict img tags to http/https only, because of MediaProxy.
  35. Meta.allow_tag_with_uri_attributes(:img, ["src"], ["http", "https"])
  36. Meta.allow_tag_with_these_attributes(:img, [
  37. "width",
  38. "height",
  39. "class",
  40. "title",
  41. "alt"
  42. ])
  43. end
  44. Meta.strip_everything_not_covered()
  45. end