Class: Rack::Protection::CookieTossing
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Base
|
|
Instance Chain:
self,
Base
|
|
Inherits: |
Rack::Protection::Base
|
Defined in: | rack-protection/lib/rack/protection/cookie_tossing.rb |
Overview
Prevented attack:: Cookie Tossing Supported browsers:: all More infos:: https://github.com/blog/1466-yummy-cookies-across-domains
Does not accept HTTP requests if the HTTP_COOKIE header contains more than one session cookie. This does not protect against a cookie overflow attack.
Options:
session_key:: The name of the session cookie (default: 'rack.session')
Constant Summary
Base
- Inherited
Class Method Summary
Base
- Inherited
Instance Attribute Summary
Instance Method Summary
- #accepts?(env) ⇒ Boolean
- #bad_cookies
- #call(env)
- #cookie_paths(path)
- #empty_cookie(host, path)
- #redirect(env)
- #remove_bad_cookies(request, response)
- #session_key
Base
- Inherited
#accepts?, #call, #debug, #default_options, | |
#default_reaction | Alias for Base#deny. |
#deny, #drop_session, #encrypt, #html?, #instrument, #origin, #random_string, #react, #referrer, #report, #safe?, #secure_compare, #session, #session?, #warn |
Constructor Details
This class inherits a constructor from Rack::Protection::Base
Instance Method Details
#accepts?(env) ⇒ Boolean
# File 'rack-protection/lib/rack/protection/cookie_tossing.rb', line 30
def accepts?(env) = env['HTTP_COOKIE'] = Rack::Utils.parse_query(, ';,') { |s| s } .each do |k, v| if (k == session_key && Array(v).size > 1) || (k != session_key && Rack::Utils.unescape(k) == session_key) << k end end .empty? end
#bad_cookies
[ GitHub ]# File 'rack-protection/lib/rack/protection/cookie_tossing.rb', line 57
def @bad_cookies ||= [] end
#call(env)
[ GitHub ]#cookie_paths(path)
[ GitHub ]# File 'rack-protection/lib/rack/protection/cookie_tossing.rb', line 61
def (path) path = '/' if path.to_s.empty? paths = [] Pathname.new(path).descend { |p| paths << p.to_s } paths end
#empty_cookie(host, path)
[ GitHub ]# File 'rack-protection/lib/rack/protection/cookie_tossing.rb', line 68
def (host, path) { value: '', domain: host, path: path, expires: Time.at(0) } end
#redirect(env)
[ GitHub ]# File 'rack-protection/lib/rack/protection/cookie_tossing.rb', line 51
def redirect(env) request = Request.new(env) warn env, "attack prevented by #{self.class}" [302, { 'content-type' => 'text/html', 'location' => request.path }, []] end
#remove_bad_cookies(request, response)
[ GitHub ]# File 'rack-protection/lib/rack/protection/cookie_tossing.rb', line 42
def (request, response) return if .empty? paths = (request.path) .each do |name| paths.each { |path| response. name, (request.host, path) } end end
#session_key
[ GitHub ]# File 'rack-protection/lib/rack/protection/cookie_tossing.rb', line 72
def session_key @session_key ||= [:session_key] end