logo

pleroma

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

twitter_text.ex (1740B)


  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. "mention hashtag"
  22. ])
  23. Meta.allow_tag_with_this_attribute_values(:a, "rel", [
  24. "tag",
  25. "nofollow",
  26. "noopener",
  27. "noreferrer"
  28. ])
  29. Meta.allow_tag_with_these_attributes(:a, ["name", "title"])
  30. # paragraphs and linebreaks
  31. Meta.allow_tag_with_these_attributes(:br, [])
  32. Meta.allow_tag_with_these_attributes(:p, [])
  33. # microformats
  34. Meta.allow_tag_with_this_attribute_values(:span, "class", ["h-card"])
  35. Meta.allow_tag_with_these_attributes(:span, [])
  36. # allow inline images for custom emoji
  37. if Pleroma.Config.get([:markup, :allow_inline_images]) do
  38. Meta.allow_tag_with_this_attribute_values(:img, "class", ["emoji"])
  39. # restrict img tags to http/https only, because of MediaProxy.
  40. Meta.allow_tag_with_uri_attributes(:img, ["src"], ["http", "https"])
  41. Meta.allow_tag_with_these_attributes(:img, [
  42. "width",
  43. "height",
  44. "title",
  45. "alt"
  46. ])
  47. end
  48. Meta.strip_everything_not_covered()
  49. end