Skip to content

Commit 70f4db2

Browse files
authored
Ignore leading dot when merging cookies
Most recent specification states that leading dots are ignored by user agents: https://httpwg.org/specs/rfc6265.html#sane-domain
1 parent 73c7174 commit 70f4db2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/rack/test/cookie_jar.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ def initialize(raw, uri = nil, default_host = DEFAULT_HOST)
3030
@name, @value = parse_query(@raw, ';').to_a.first
3131
@options = parse_query(options, ';')
3232

33-
if @options['domain']
33+
if domain = @options['domain']
3434
@exact_domain_match = false
35+
domain[0] = '' if domain[0] == '.'
3536
else
3637
# If the domain attribute is not present in the cookie,
3738
# the domain must match exactly.

spec/rack/test/cookie_jar_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
jar_clone.to_hash.must_be_empty
1818
end
1919

20+
it 'ignores leading dot in domain' do
21+
jar = Rack::Test::CookieJar.new
22+
jar << Rack::Test::Cookie.new('a=c; domain=.lithostech.com', URI('https://lithostech.com'))
23+
jar.get_cookie('a').domain.must_equal 'lithostech.com'
24+
end
25+
2026
it '#[] and []= should get and set cookie values' do
2127
jar = Rack::Test::CookieJar.new
2228
jar[cookie_name].must_be_nil

0 commit comments

Comments
 (0)