Sha256: 6738d186918961e3bd43d4698558df14b24918a0190eea80ad57f40ce9d45ee7

Contents?: true

Size: 885 Bytes

Versions: 6

Compression:

Stored size: 885 Bytes

Contents

module SecureHeaders
  class XFOBuildError < StandardError; end
  class XFrameOptions < Header
    module Constants
      XFO_HEADER_NAME = "X-Frame-Options"
      DEFAULT_VALUE = 'SAMEORIGIN'
      VALID_XFO_HEADER = /\A(SAMEORIGIN\z|DENY\z|ALLOW-FROM[:\s])/i
      CONFIG_KEY = :x_frame_options
    end
    include Constants

    def initialize(config = nil)
      @config = config
      validate_config unless @config.nil?
    end

    def name
      XFO_HEADER_NAME
    end

    def value
      case @config
      when NilClass
        DEFAULT_VALUE
      when String
        @config
      else
        @config[:value]
      end
    end

    private

    def validate_config
      value = @config.is_a?(Hash) ? @config[:value] : @config
      unless value =~ VALID_XFO_HEADER
        raise XFOBuildError.new("Value must be SAMEORIGIN|DENY|ALLOW-FROM:")
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
secure_headers-2.4.4 lib/secure_headers/headers/x_frame_options.rb
secure_headers-2.4.3 lib/secure_headers/headers/x_frame_options.rb
secure_headers-2.4.2 lib/secure_headers/headers/x_frame_options.rb
secure_headers-2.4.1 lib/secure_headers/headers/x_frame_options.rb
secure_headers-2.4.0 lib/secure_headers/headers/x_frame_options.rb
secure_headers-2.3.0 lib/secure_headers/headers/x_frame_options.rb