Sha256: 4a4486c031d7805f56e6fe40339be557468f0c35f56e396be922f494c3a620eb

Contents?: true

Size: 1.4 KB

Versions: 14

Compression:

Stored size: 1.4 KB

Contents

class Sanitize
  module Config

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

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

      attributes: {
        'a'      => RELAXED[:attributes]['a'] + %w(target),
        'audio'  => %w[controls],
        'embed'  => %w[height src type width],
        'iframe' => %w[allowfullscreen frameborder height scrolling src width],
        'source' => %w[src type],
        'video'  => %w[controls height loop width],
        'div'    => [: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 noopener'
          else
            a_tag.remove_attribute('target')
          end
        end
      ],

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
onebox-1.8.36 lib/onebox/sanitize_config.rb
onebox-1.8.35 lib/onebox/sanitize_config.rb
onebox-1.8.34 lib/onebox/sanitize_config.rb
onebox-1.8.33 lib/onebox/sanitize_config.rb
onebox-1.8.32 lib/onebox/sanitize_config.rb
onebox-1.8.31 lib/onebox/sanitize_config.rb
onebox-1.8.30 lib/onebox/sanitize_config.rb
onebox-1.8.29 lib/onebox/sanitize_config.rb
onebox-1.8.28 lib/onebox/sanitize_config.rb
onebox-1.8.27 lib/onebox/sanitize_config.rb
onebox-1.8.26 lib/onebox/sanitize_config.rb
onebox-1.8.25 lib/onebox/sanitize_config.rb
onebox-1.8.24 lib/onebox/sanitize_config.rb
onebox-1.8.23 lib/onebox/sanitize_config.rb