mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-35121: prefix dot in domain for proper subdomain validation (GH-10258)
Don't send cookies of domain A without Domain attribute to domain B when domain A is a suffix match of domain B while using a cookiejar with `http.cookiejar.DefaultCookiePolicy` policy. Patch by Karthikeyan Singaravelan.
This commit is contained in:
parent
738c19f4c5
commit
ca7fe50635
3 changed files with 45 additions and 2 deletions
|
@ -440,6 +440,7 @@ class CookieTests(unittest.TestCase):
|
|||
("http://foo.bar.com/", ".foo.bar.com", True),
|
||||
("http://foo.bar.com/", "foo.bar.com", True),
|
||||
("http://foo.bar.com/", ".bar.com", True),
|
||||
("http://foo.bar.com/", "bar.com", True),
|
||||
("http://foo.bar.com/", "com", True),
|
||||
("http://foo.com/", "rhubarb.foo.com", False),
|
||||
("http://foo.com/", ".foo.com", True),
|
||||
|
@ -450,6 +451,8 @@ class CookieTests(unittest.TestCase):
|
|||
("http://foo/", "foo", True),
|
||||
("http://foo/", "foo.local", True),
|
||||
("http://foo/", ".local", True),
|
||||
("http://barfoo.com", ".foo.com", False),
|
||||
("http://barfoo.com", "foo.com", False),
|
||||
]:
|
||||
request = urllib.request.Request(url)
|
||||
r = pol.domain_return_ok(domain, request)
|
||||
|
@ -984,6 +987,33 @@ class CookieTests(unittest.TestCase):
|
|||
c.add_cookie_header(req)
|
||||
self.assertFalse(req.has_header("Cookie"))
|
||||
|
||||
c.clear()
|
||||
|
||||
pol.set_blocked_domains([])
|
||||
req = urllib.request.Request("http://acme.com/")
|
||||
res = FakeResponse(headers, "http://acme.com/")
|
||||
cookies = c.make_cookies(res, req)
|
||||
c.extract_cookies(res, req)
|
||||
self.assertEqual(len(c), 1)
|
||||
|
||||
req = urllib.request.Request("http://acme.com/")
|
||||
c.add_cookie_header(req)
|
||||
self.assertTrue(req.has_header("Cookie"))
|
||||
|
||||
req = urllib.request.Request("http://badacme.com/")
|
||||
c.add_cookie_header(req)
|
||||
self.assertFalse(pol.return_ok(cookies[0], req))
|
||||
self.assertFalse(req.has_header("Cookie"))
|
||||
|
||||
p = pol.set_blocked_domains(["acme.com"])
|
||||
req = urllib.request.Request("http://acme.com/")
|
||||
c.add_cookie_header(req)
|
||||
self.assertFalse(req.has_header("Cookie"))
|
||||
|
||||
req = urllib.request.Request("http://badacme.com/")
|
||||
c.add_cookie_header(req)
|
||||
self.assertFalse(req.has_header("Cookie"))
|
||||
|
||||
def test_secure(self):
|
||||
for ns in True, False:
|
||||
for whitespace in " ", "":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue