Sha256: 43f5ca17e222b6a0288a0c5873099e8b645c607979aaae3176c21ea99ec4dee6

Contents?: true

Size: 1.7 KB

Versions: 20

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

class Sanitize
  module Config

    HTTP_PROTOCOLS ||= ['http', 'https', :relative].freeze

    ONEBOX ||= freeze_config merge(RELAXED,
      elements: RELAXED[:elements] + %w[audio embed iframe source video svg path],

      attributes: {
        'a' => RELAXED[:attributes]['a'] + %w(target),
        'audio' => %w[controls],
        'embed' => %w[height src type width],
        'iframe' => %w[allowfullscreen frameborder height scrolling src width data-original-href],
        'source' => %w[src type],
        'video' => %w[controls height loop width autoplay muted poster],
        'path' => %w[d],
        'svg' => ['aria-hidden', 'width', 'height', 'viewbox'],
        'div' => [:data], # any data-* attributes,
        'span' => [:data], # any data-* attributes
      },

      add_attributes: {
        'iframe' => {
          'seamless' => 'seamless',
          'sandbox' => 'allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox' \
                       ' allow-presentation',
        }
      },

      transformers: (RELAXED[:transformers] || []) + [
        lambda do |env|
          next unless env[:node_name] == 'a'
          a_tag = env[:node]
          a_tag['href'] ||= '#'
          if a_tag['href'] =~ %r{^(?:[a-z]+:)?//}
            a_tag['rel'] = 'nofollow ugc noopener'
          else
            a_tag.remove_attribute('target')
          end
        end
      ],

      protocols: {
        'embed' => { 'src' => HTTP_PROTOCOLS },
        'iframe' => { 'src' => HTTP_PROTOCOLS },
        'source' => { 'src' => HTTP_PROTOCOLS },
      },

      css: {
        properties: RELAXED[:css][:properties] + %w[--aspect-ratio]
      }
    )
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
onebox-2.0.1 lib/onebox/sanitize_config.rb
onebox-2.0.0 lib/onebox/sanitize_config.rb
onebox-1.9.30 lib/onebox/sanitize_config.rb
onebox-1.9.29 lib/onebox/sanitize_config.rb
onebox-1.9.28.4 lib/onebox/sanitize_config.rb
onebox-1.9.28.3 lib/onebox/sanitize_config.rb
onebox-1.9.28.2 lib/onebox/sanitize_config.rb
onebox-1.9.28.1 lib/onebox/sanitize_config.rb
onebox-1.9.28 lib/onebox/sanitize_config.rb
onebox-1.9.27.2 lib/onebox/sanitize_config.rb
onebox-1.9.27.1 lib/onebox/sanitize_config.rb
onebox-1.9.26 lib/onebox/sanitize_config.rb
onebox-1.9.25 lib/onebox/sanitize_config.rb
onebox-1.9.24 lib/onebox/sanitize_config.rb
onebox-1.9.23 lib/onebox/sanitize_config.rb
onebox-1.9.22 lib/onebox/sanitize_config.rb
onebox-1.9.21 lib/onebox/sanitize_config.rb
onebox-1.9.20 lib/onebox/sanitize_config.rb
onebox-1.9.19 lib/onebox/sanitize_config.rb
onebox-1.9.18 lib/onebox/sanitize_config.rb