Sha256: 8a7cd170f054bbc4782463bf1560cc9d69ea563d058997d307c6c81063cb75a5

Contents?: true

Size: 1.42 KB

Versions: 30

Compression:

Stored size: 1.42 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 autoplay muted poster],
        '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

30 entries across 30 versions & 1 rubygems

Version Path
onebox-1.8.68 lib/onebox/sanitize_config.rb
onebox-1.8.67 lib/onebox/sanitize_config.rb
onebox-1.8.66 lib/onebox/sanitize_config.rb
onebox-1.8.65 lib/onebox/sanitize_config.rb
onebox-1.8.64 lib/onebox/sanitize_config.rb
onebox-1.8.63 lib/onebox/sanitize_config.rb
onebox-1.8.62 lib/onebox/sanitize_config.rb
onebox-1.8.61 lib/onebox/sanitize_config.rb
onebox-1.8.60 lib/onebox/sanitize_config.rb
onebox-1.8.59 lib/onebox/sanitize_config.rb
onebox-1.8.58 lib/onebox/sanitize_config.rb
onebox-1.8.57 lib/onebox/sanitize_config.rb
onebox-1.8.55 lib/onebox/sanitize_config.rb
onebox-1.8.54 lib/onebox/sanitize_config.rb
onebox-1.8.53 lib/onebox/sanitize_config.rb
onebox-1.8.52 lib/onebox/sanitize_config.rb
onebox-1.8.51 lib/onebox/sanitize_config.rb
onebox-1.8.50 lib/onebox/sanitize_config.rb
onebox-1.8.49 lib/onebox/sanitize_config.rb
onebox-1.8.48 lib/onebox/sanitize_config.rb