Skip to content

Commit

Permalink
Merge pull request #47087 from jhawthorn/cookie_domain
Browse files Browse the repository at this point in the history
Fix cookie domain for `domain: all` on two letter single level TLD
  • Loading branch information
jhawthorn committed Jan 24, 2023
2 parents 03082f3 + 941e0cd commit f6e36c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/middleware/cookies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def handle_options(options)
# Case where tld_length is not provided
else
# Regular TLDs
if !(/([^.]{2,3}\.[^.]{2})$/.match?(request.host))
if !(/\.[^.]{2,3}\.[^.]{2}\z/.match?(request.host))
cookie_domain = dot_splitted_host.last(2).join(".")
# **.**, ***.** style TLDs like co.uk and com.au
else
Expand Down
14 changes: 14 additions & 0 deletions actionpack/test/dispatch/cookies_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,20 @@ def test_cookie_with_all_domain_option_using_uk_style_tld
assert_set_cookie_header "user_name=rizwanreza; domain=.nextangle.co.uk; path=/; SameSite=Lax"
end

def test_cookie_with_all_domain_option_using_two_letter_one_level_tld
@request.host = "hawth.ca"
get :set_cookie_with_domain
assert_response :success
assert_set_cookie_header "user_name=rizwanreza; domain=.hawth.ca; path=/; SameSite=Lax"
end

def test_cookie_with_all_domain_option_using_two_letter_one_level_tld_and_subdomain
@request.host = "x.hawth.ca"
get :set_cookie_with_domain
assert_response :success
assert_set_cookie_header "user_name=rizwanreza; domain=.hawth.ca; path=/; SameSite=Lax"
end

def test_cookie_with_all_domain_option_using_uk_style_tld_and_two_subdomains
@request.host = "x.nextangle.co.uk"
get :set_cookie_with_domain
Expand Down

0 comments on commit f6e36c9

Please sign in to comment.