Class: SafeCookies::Configuration
- Inherits:
-
Object
- Object
- SafeCookies::Configuration
- Defined in:
- lib/safe_cookies/configuration.rb
Instance Attribute Summary collapse
-
#correct_cookie_paths_timestamp ⇒ Object
readonly
Returns the value of attribute correct_cookie_paths_timestamp.
-
#fix_cookie_paths ⇒ Object
readonly
Returns the value of attribute fix_cookie_paths.
-
#ignored_cookies ⇒ Object
readonly
Returns the value of attribute ignored_cookies.
-
#log_unknown_cookies ⇒ Object
Returns the value of attribute log_unknown_cookies.
-
#registered_cookies ⇒ Object
readonly
Returns the value of attribute registered_cookies.
Instance Method Summary collapse
- #fix_paths(options = {}) ⇒ Object
-
#ignore_cookie(name_or_regex) ⇒ Object
Ignore cookies that you don’t control like this:.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #insecure_cookie?(name) ⇒ Boolean
-
#register_cookie(name, options) ⇒ Object
Register cookies you expect to receive.
- #scriptable_cookie?(name) ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
20 21 22 23 24 25 |
# File 'lib/safe_cookies/configuration.rb', line 20 def initialize self. = {} self. = [] self. = [] self. = [] end |
Instance Attribute Details
#correct_cookie_paths_timestamp ⇒ Object
Returns the value of attribute correct_cookie_paths_timestamp.
17 18 19 |
# File 'lib/safe_cookies/configuration.rb', line 17 def @correct_cookie_paths_timestamp end |
#fix_cookie_paths ⇒ Object
Returns the value of attribute fix_cookie_paths.
17 18 19 |
# File 'lib/safe_cookies/configuration.rb', line 17 def @fix_cookie_paths end |
#ignored_cookies ⇒ Object
Returns the value of attribute ignored_cookies.
17 18 19 |
# File 'lib/safe_cookies/configuration.rb', line 17 def @ignored_cookies end |
#log_unknown_cookies ⇒ Object
Returns the value of attribute log_unknown_cookies.
16 17 18 |
# File 'lib/safe_cookies/configuration.rb', line 16 def @log_unknown_cookies end |
#registered_cookies ⇒ Object
Returns the value of attribute registered_cookies.
17 18 19 |
# File 'lib/safe_cookies/configuration.rb', line 17 def @registered_cookies end |
Instance Method Details
#fix_paths(options = {}) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/safe_cookies/configuration.rb', line 59 def fix_paths( = {}) .has_key?(:for_cookies_secured_before) or raise MissingOptionError.new("Was told to fix paths without the :for_cookies_secured_before timestamp.") self. = true self. = [:for_cookies_secured_before] end |
#ignore_cookie(name_or_regex) ⇒ Object
Ignore cookies that you don’t control like this:
'ignored_cookie'
/^__utm/
55 56 57 |
# File 'lib/safe_cookies/configuration.rb', line 55 def (name_or_regex) self. << name_or_regex end |
#insecure_cookie?(name) ⇒ Boolean
66 67 68 |
# File 'lib/safe_cookies/configuration.rb', line 66 def (name) .include? name end |
#register_cookie(name, options) ⇒ Object
Register cookies you expect to receive. The middleware will rewrite all registered cookies it receives, making them both secure and http_only.
Unfortunately, the client won’t ever tell us if the cookie was originally sent with flags such as “secure” or which expiry date it currently has: tools.ietf.org/html/rfc6265#section-4.2.2
Therefore, specify an expiry, and more options if needed:
:expire_after => 1.year
:secure => false
:http_only = false
:path => '/foo/path'
41 42 43 44 45 46 47 48 49 |
# File 'lib/safe_cookies/configuration.rb', line 41 def (name, ) name.is_a?(String) or raise "Cookie name must be a String" .has_key?(:expire_after) or raise MissingOptionError.new("Cookie #{name.inspect} was registered without an expiry") raise NotImplementedError if .has_key?(:domain) [name] = ( || {}).freeze << name if [:secure] == false << name if [:http_only] == false end |
#scriptable_cookie?(name) ⇒ Boolean
70 71 72 |
# File 'lib/safe_cookies/configuration.rb', line 70 def (name) .include? name end |