Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Lib/http/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,9 @@ def domain_match(A, B):
if not is_HDN(A):
return False
i = A.rfind(B)
if i == -1 or i == 0:
# A does not have form NB, or N is the empty string
if i == -1 or i == 0 or i + len(B) != len(A):
# A does not have form NB, N is the empty string, or B is not a
# suffix of A (so A only contains B as an interior substring)
return False
if not B.startswith("."):
return False
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_http_cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,9 @@ def test_domain_match(self):
self.assertFalse(domain_match("blah.blah", ""))
self.assertFalse(domain_match("", ".rhubarb.rhubarb"))
self.assertTrue(domain_match("", ""))
# B must be a suffix of A, not just an interior substring
self.assertFalse(domain_match("www.acme.com.evil.org", ".acme.com"))
self.assertFalse(domain_match("a.b.c.com.example.net", ".c.com"))

self.assertTrue(user_domain_match("acme.com", "acme.com"))
self.assertFalse(user_domain_match("acme.com", ".acme.com"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:func:`http.cookiejar.domain_match` now requires the second domain to be a
suffix of the first instead of merely an interior substring, so a host such
as ``www.example.com.evil`` no longer domain-matches ``.example.com``.
Loading