logo

pleroma

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

twitter_text.ex (1717B)


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