闭社主体 forked from https://github.com/tootsuite/mastodon
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.

49 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. class Sanitize
  3. module Config
  4. HTTP_PROTOCOLS ||= ['http', 'https', :relative].freeze
  5. MASTODON_STRICT ||= freeze_config(
  6. elements: %w(p br span a),
  7. attributes: {
  8. 'a' => %w(href),
  9. 'span' => %w(class),
  10. },
  11. add_attributes: {
  12. 'a' => {
  13. 'rel' => 'nofollow noopener',
  14. 'target' => '_blank',
  15. },
  16. },
  17. protocols: {
  18. 'a' => { 'href' => HTTP_PROTOCOLS },
  19. }
  20. )
  21. MASTODON_OEMBED ||= freeze_config merge(
  22. RELAXED,
  23. elements: RELAXED[:elements] + %w(audio embed iframe source video),
  24. attributes: merge(
  25. RELAXED[:attributes],
  26. 'audio' => %w(controls),
  27. 'embed' => %w(height src type width),
  28. 'iframe' => %w(allowfullscreen frameborder height scrolling src width),
  29. 'source' => %w(src type),
  30. 'video' => %w(controls height loop width),
  31. 'div' => [:data]
  32. ),
  33. protocols: merge(
  34. RELAXED[:protocols],
  35. 'embed' => { 'src' => HTTP_PROTOCOLS },
  36. 'iframe' => { 'src' => HTTP_PROTOCOLS },
  37. 'source' => { 'src' => HTTP_PROTOCOLS }
  38. )
  39. )
  40. end
  41. end