Module: CookieJar::CookieValidation

Defined in:
lib/core_extensions/cookiejar/cookie_validation.rb

Class Method Summary collapse

Class Method Details

.domains_match(tested_domain, base_domain) ⇒ Object

Re-opening the CookieValidation module to rewrite the domains_match method to skip the validation of domains. Open issue at github.com/restforce/restforce/issues/120


10
11
12
13
14
15
16
17
18
19
# File 'lib/core_extensions/cookiejar/cookie_validation.rb', line 10

def self.domains_match(tested_domain, base_domain)
  return true if tested_domain[-15..].eql?('.salesforce.com')

  # original implementation
  base = effective_host base_domain
  search_domains = compute_search_domains_for_host base
  search_domains.find do |domain|
    domain == tested_domain
  end
end

Implements github.com/dwaite/cookiejar/commit/adb79c0a14c2b347c5289e79379a1acfe34bf388 which is not part of the cookiejar gem yet and is required to prevent Unknown cookie parameter 'samesite' (CookieJar::InvalidCookieError)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/core_extensions/cookiejar/cookie_validation.rb', line 24

def self.parse_set_cookie(set_cookie_value)
  args = {}
  params = set_cookie_value.split(/;\s*/)

  first = true
  params.each do |param|
    result = PARAM1.match param
    unless result
      fail InvalidCookieError,
        "Invalid cookie parameter in cookie '#{set_cookie_value}'"
    end
    key = result[1].downcase.to_sym
    keyvalue = result[2]
    if first
      args[:name] = result[1]
      args[:value] = keyvalue
      first = false
    else
      case key
      when :expires
        begin
          args[:expires_at] = Time.parse keyvalue
        rescue ArgumentError
          raise unless $ERROR_INFO.message == 'time out of range'

          args[:expires_at] = Time.at(0x7FFFFFFF)
        end
      when :'max-age'
        args[:max_age] = keyvalue.to_i
      when :domain, :path
        args[key] = keyvalue
      when :secure
        args[:secure] = true
      when :httponly
        args[:http_only] = true
      when :samesite
        args[:samesite] = keyvalue.downcase
      else
        fail InvalidCookieError, "Unknown cookie parameter '#{key}'"
      end
    end
  end
  args[:version] = 0
  args
end