Class: SiteInspector::Endpoint::Hsts

Inherits:
Check
  • Object
show all
Defined in:
lib/site-inspector/checks/hsts.rb

Overview

Utility parser for HSTS headers. RFC: tools.ietf.org/html/rfc6797

Instance Attribute Summary

Attributes inherited from Check

#endpoint

Instance Method Summary collapse

Methods inherited from Check

enabled=, enabled?, #host, #initialize, #inspect, #name, name, #request, #response

Constructor Details

This class inherits a constructor from SiteInspector::Endpoint::Check

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/site-inspector/checks/hsts.rb', line 26

def enabled?
  return false unless max_age

  max_age.positive?
end

#include_subdomains?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/site-inspector/checks/hsts.rb', line 18

def include_subdomains?
  pairs.key?(:includesubdomains)
end

#max_ageObject



14
15
16
# File 'lib/site-inspector/checks/hsts.rb', line 14

def max_age
  pairs[:"max-age"].to_i
end

#preload?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/site-inspector/checks/hsts.rb', line 22

def preload?
  pairs.key?(:preload)
end

#preload_ready?Boolean

Google’s minimum max-age for automatic preloading

Returns:

  • (Boolean)


33
34
35
# File 'lib/site-inspector/checks/hsts.rb', line 33

def preload_ready?
  include_subdomains? && preload? && max_age >= 10_886_400
end

#to_hObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/site-inspector/checks/hsts.rb', line 37

def to_h
  {
    valid: valid?,
    max_age: max_age,
    include_subdomains: include_subdomains?,
    preload: preload?,
    enabled: enabled?,
    preload_ready: preload_ready?
  }
end

#valid?Boolean

Returns:

  • (Boolean)


8
9
10
11
12
# File 'lib/site-inspector/checks/hsts.rb', line 8

def valid?
  return false unless header

  pairs.none? { |key, value| "#{key}#{value}" =~ /[\s'"]/ }
end