Module CookieJar::CookieValidation
In: lib/cookiejar/cookie_validation.rb

Contains logic to parse and validate cookie headers

Methods

Classes and Modules

Module CookieJar::CookieValidation::PATTERN

Constants

BASE_HOSTNAME = /#{PATTERN::BASE_HOSTNAME}/
BASE_PATH = /\A((?:[^\/?#]*\/)*)/
IPADDR = /\A#{PATTERN::IPV4ADDR}\Z|\A#{PATTERN::IPV6ADDR}\Z/
HDN = /\A#{PATTERN::HOSTNAME}\Z/
TOKEN = /\A#{PATTERN::TOKEN}\Z/
PARAM1 = /\A(#{PATTERN::TOKEN})(?:=#{PATTERN::VALUE1})?\Z/
PARAM2 = Regexp.new "(#{PATTERN::TOKEN})(?:=(#{PATTERN::VALUE2}))?(?:\\Z|;)", '', 'n'

Public Class methods

Given a URI, compute the relevant search domains for pre-existing cookies. This includes all the valid dotted forms for a named or IP domains.

@param [String, URI] request_uri requested uri @return [Array<String>] all cookie domain values which would match the

  requested uri

Given a host, compute the relevant search domains for pre-existing cookies

@param [String] host host being requested @return [Array<String>] all cookie domain values which would match the

  requested uri

Compute the base of a path, for default cookie path assignment

@param [String, URI, Cookie] path, or object holding path @return base path (all characters up to final ’/’)

Attempt to decipher a partially decoded version of text cookie values

Processes cookie domain data using the following rules: Domains strings of the form .foo.com match ‘foo.com’ and all immediate subdomains of ‘foo.com’. Domain strings specified of the form ‘foo.com’ are modified to ’.foo.com’, and as such will still apply to subdomains.

Cookies without an explicit domain will have their domain value taken directly from the URL, and will NOT have any leading dot applied. For example, a request to foo.com/ will cause an entry for ‘foo.com’ to be created - which applies to foo.com but no subdomain.

Note that this will not attempt to detect a mismatch of the request uri domain and explicitly specified cookie domain

@param [String, URI] request_uri originally requested URI @param [String] cookie domain value @return [String] effective host

Processes cookie path data using the following rules: Paths are separated by ’/’ characters, and accepted values are truncated to the last ’/’ character. If no path is specified in the cookie, a path value will be taken from the request URI which was used for the site.

Note that this will not attempt to detect a mismatch of the request uri domain and explicitly specified cookie path

@param [String,URI] request URI yielding this cookie @param [String] path on cookie

Compare a tested domain against the base domain to see if they match, or if the base domain is reachable.

@param [String] tested_domain domain to be tested against @param [String] base_domain new domain being tested @return [String,nil] matching domain on success, nil on failure

Compute the effective host (RFC 2965, section 1)

Has the added additional logic of searching for interior dots specifically, and matches colons to prevent .local being suffixed on IPv6 addresses

@param [String, URI] host_or_uridomain name, or absolute URI @return [String] effective host per RFC rules

Compute the reach of a hostname (RFC 2965, section 1) Determines the next highest superdomain

@param [String,URI,Cookie] hostname hostname, or object holding hostname @return [String,nil] next highest hostname, or nil if none

Break apart a traditional (non RFC 2965) cookie value into its core components. This does not do any validation, or defaulting of values based on requested URI

@param [String] set_cookie_value a Set-Cookie header formatted cookie

  definition

@return [Hash] Contains the parsed values of the cookie

Break apart a RFC 2965 cookie value into its core components. This does not do any validation, or defaulting of values based on requested URI

@param [String] set_cookie_value a Set-Cookie2 header formatted cookie

  definition

@return [Hash] Contains the parsed values of the cookie

Converts an input cookie or uri to a string representing the domain. Assume strings are already domains. Value may not be an effective host.

@param [String, URI, Cookie] object containing the domain @return [String] domain information.

Converts an input cookie or uri to a string representing the path. Assume strings are already paths

@param [String, URI, Cookie] object containing the path @return [String] path information

Converts the input object to a URI (if not already a URI)

@param [String, URI] request_uri URI we are normalizing @param [URI] URI representation of input string, or original URI

Check whether a cookie meets all of the rules to be created, based on its internal settings and the URI it came from.

@param [String,URI] request_uri originally requested URI @param [Cookie] cookie object @param [true] will always return true on success @raise [InvalidCookieError] on failures, containing all validation errors

Parse a RFC 2965 value and convert to a literal string

[Validate]