Class: Arachni::HTTP::CookieJar
- Includes:
- Utilities
- Defined in:
- lib/arachni/http/cookie_jar.rb
Overview
Basic CookieJar implementation.
Defined Under Namespace
Classes: Error
Class Method Summary collapse
Instance Method Summary collapse
-
#<<(cookies) ⇒ CookieJar
‘self`.
- #==(other) ⇒ Object
-
#any? ⇒ Bool
‘true` if cookiejar is not empty, `false` otherwise.
-
#clear ⇒ Object
Empties the cookiejar.
-
#cookies(include_expired = false) ⇒ Array<Cookie>
All cookies.
-
#empty? ⇒ Bool
‘true` if cookiejar is empty, `false` otherwise.
-
#for_url(url) ⇒ Array<Cookie>
URL which should be sent to the resource at ‘url`.
- #hash ⇒ Object
-
#initialize(cookie_jar_file = nil) ⇒ CookieJar
constructor
A new instance of CookieJar.
-
#load(cookie_jar_file, url = '') ⇒ CookieJar
Loads cookies from a Netscape cookiejar file.
- #merge!(other) ⇒ Object
-
#update(cookies) ⇒ CookieJar
Updates the jar with ‘cookies`.
Methods included from Utilities
#available_port, #bytes_to_kilobytes, #bytes_to_megabytes, #caller_name, #caller_path, #cookie_decode, #cookie_encode, #cookies_from_document, #cookies_from_file, #cookies_from_response, #exception_jail, #exclude_path?, #follow_protocol?, #form_decode, #form_encode, #forms_from_document, #forms_from_response, #full_and_absolute_url?, #generate_token, #get_path, #hms_to_seconds, #html_decode, #html_encode, #include_path?, #links_from_document, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_set_cookie, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #random_seed, #redundant_path?, #regexp_array_match, #remove_constants, #request_parse_body, #seconds_to_hms, #skip_page?, #skip_path?, #skip_resource?, #skip_response?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parse_query, #uri_parser, #uri_rewrite
Constructor Details
#initialize(cookie_jar_file = nil) ⇒ CookieJar
Returns a new instance of CookieJar.
41 42 43 44 |
# File 'lib/arachni/http/cookie_jar.rb', line 41 def initialize( = nil ) @domains = {} load( ) if end |
Class Method Details
.from_file(*args) ⇒ Arachni::HTTP::CookieJar
Same as #initialize.
35 36 37 |
# File 'lib/arachni/http/cookie_jar.rb', line 35 def self.from_file( *args ) new.load( *args ) end |
Instance Method Details
#<<(cookies) ⇒ CookieJar
Returns ‘self`.
68 69 70 71 72 73 |
# File 'lib/arachni/http/cookie_jar.rb', line 68 def <<( ) [].flatten.compact.each do || ((@domains[.domain] ||= {})[.path] ||= {})[.name] = .dup end self end |
#==(other) ⇒ Object
171 172 173 |
# File 'lib/arachni/http/cookie_jar.rb', line 171 def ==( other ) hash == other.hash end |
#any? ⇒ Bool
Returns ‘true` if cookiejar is not empty, `false` otherwise.
166 167 168 |
# File 'lib/arachni/http/cookie_jar.rb', line 166 def any? !empty? end |
#clear ⇒ Object
Empties the cookiejar.
154 155 156 |
# File 'lib/arachni/http/cookie_jar.rb', line 154 def clear @domains.clear end |
#cookies(include_expired = false) ⇒ Array<Cookie>
Returns All cookies.
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/arachni/http/cookie_jar.rb', line 136 def ( include_expired = false ) @domains.values.map do |paths| paths.values.map do || if !include_expired .values.reject{ |c| c.expired? } else .values end end end.flatten.compact end |
#empty? ⇒ Bool
Returns ‘true` if cookiejar is empty, `false` otherwise.
160 161 162 |
# File 'lib/arachni/http/cookie_jar.rb', line 160 def empty? @domains.empty? end |
#for_url(url) ⇒ Array<Cookie>
Returns URL which should be sent to the resource at ‘url`.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/arachni/http/cookie_jar.rb', line 111 def for_url( url ) uri = to_uri( url ) request_path = uri.path request_domain = uri.host return [] if !request_domain || !request_path @domains.map do |domain, paths| next if !in_domain?( domain, request_domain ) paths.map do |path, | next if !request_path.start_with?( path ) .values.reject{ |c| c.expired? } end end.flatten.compact.sort do |lhs, rhs| rhs.path.length <=> lhs.path.length end end |
#hash ⇒ Object
175 176 177 |
# File 'lib/arachni/http/cookie_jar.rb', line 175 def hash .map(&:to_s).hash end |
#load(cookie_jar_file, url = '') ⇒ CookieJar
Loads cookies from a Netscape cookiejar file.
54 55 56 57 58 59 60 61 |
# File 'lib/arachni/http/cookie_jar.rb', line 54 def load( , url = '' ) # make sure that the provided cookie-jar file exists if !File.exist?( ) fail Error::CookieJarFileNotFound, "Cookie-jar '#{}' doesn't exist." end update( ( url, ) ) self end |
#merge!(other) ⇒ Object
149 150 151 |
# File 'lib/arachni/http/cookie_jar.rb', line 149 def merge!( other ) update other. end |
#update(cookies) ⇒ CookieJar
Updates the jar with ‘cookies`.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/arachni/http/cookie_jar.rb', line 81 def update( ) [].flatten.compact.each do |c| self << case c when String begin Cookie.from_string( ::Arachni::Options.url.to_s, c ) rescue Cookie.( ::Arachni::Options.url.to_s, c ) end when Hash next if c.empty? if c.size > 1 Cookie.new( { url: ::Arachni::Options.url.to_s }.merge( c ) ) else Cookie.new( url: ::Arachni::Options.url.to_s, inputs: c ) end when Cookie c end end self end |