Class: SecureHeaders::ClearSiteData

Inherits:
Object
  • Object
show all
Defined in:
lib/secure_headers/headers/clear_site_data.rb

Constant Summary collapse

HEADER_NAME =
"clear-site-data".freeze
CACHE =

Valid ‘types`

"cache".freeze
COOKIES =
"cookies".freeze
STORAGE =
"storage".freeze
EXECUTION_CONTEXTS =
"executionContexts".freeze
ALL_TYPES =
[CACHE, COOKIES, STORAGE, EXECUTION_CONTEXTS]

Class Method Summary collapse

Class Method Details

.make_header(config = nil, user_agent = nil) ⇒ Object

Public: make an clear-site-data header name, value pair

Returns nil if not configured, returns header name and value if configured.



18
19
20
21
22
23
24
25
26
27
# File 'lib/secure_headers/headers/clear_site_data.rb', line 18

def make_header(config = nil, user_agent = nil)
  case config
  when nil, OPT_OUT, []
    # noop
  when Array
    [HEADER_NAME, make_header_value(config)]
  when true
    [HEADER_NAME, make_header_value(ALL_TYPES)]
  end
end

.make_header_value(types) ⇒ Object

Public: Transform a clear-site-data config (an Array of Strings) into a String that can be used as the value for the clear-site-data header.

types - An Array of String of types of data to clear.

Returns a String of quoted values that are comma separated.



48
49
50
# File 'lib/secure_headers/headers/clear_site_data.rb', line 48

def make_header_value(types)
  types.map { |t| %("#{t}") }.join(", ")
end

.validate_config!(config) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/secure_headers/headers/clear_site_data.rb', line 29

def validate_config!(config)
  case config
  when nil, OPT_OUT, true
    # valid
  when Array
    unless config.all? { |t| t.is_a?(String) }
      raise ClearSiteDataConfigError.new("types must be Strings")
    end
  else
    raise ClearSiteDataConfigError.new("config must be an Array of Strings or `true`")
  end
end