|
|
71928b |
diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py
|
|
|
71928b |
index adf956d..97599d4 100644
|
|
|
71928b |
--- a/Lib/http/cookiejar.py
|
|
|
71928b |
+++ b/Lib/http/cookiejar.py
|
|
|
71928b |
@@ -1148,6 +1148,11 @@ class DefaultCookiePolicy(CookiePolicy):
|
|
|
71928b |
req_host, erhn = eff_request_host(request)
|
|
|
71928b |
domain = cookie.domain
|
|
|
71928b |
|
|
|
71928b |
+ if domain and not domain.startswith("."):
|
|
|
71928b |
+ dotdomain = "." + domain
|
|
|
71928b |
+ else:
|
|
|
71928b |
+ dotdomain = domain
|
|
|
71928b |
+
|
|
|
71928b |
# strict check of non-domain cookies: Mozilla does this, MSIE5 doesn't
|
|
|
71928b |
if (cookie.version == 0 and
|
|
|
71928b |
(self.strict_ns_domain & self.DomainStrictNonDomain) and
|
|
|
71928b |
@@ -1160,7 +1165,7 @@ class DefaultCookiePolicy(CookiePolicy):
|
|
|
71928b |
_debug(" effective request-host name %s does not domain-match "
|
|
|
71928b |
"RFC 2965 cookie domain %s", erhn, domain)
|
|
|
71928b |
return False
|
|
|
71928b |
- if cookie.version == 0 and not ("."+erhn).endswith(domain):
|
|
|
71928b |
+ if cookie.version == 0 and not ("."+erhn).endswith(dotdomain):
|
|
|
71928b |
_debug(" request-host %s does not match Netscape cookie domain "
|
|
|
71928b |
"%s", req_host, domain)
|
|
|
71928b |
return False
|
|
|
71928b |
@@ -1174,7 +1179,11 @@ class DefaultCookiePolicy(CookiePolicy):
|
|
|
71928b |
req_host = "."+req_host
|
|
|
71928b |
if not erhn.startswith("."):
|
|
|
71928b |
erhn = "."+erhn
|
|
|
71928b |
- if not (req_host.endswith(domain) or erhn.endswith(domain)):
|
|
|
71928b |
+ if domain and not domain.startswith("."):
|
|
|
71928b |
+ dotdomain = "." + domain
|
|
|
71928b |
+ else:
|
|
|
71928b |
+ dotdomain = domain
|
|
|
71928b |
+ if not (req_host.endswith(dotdomain) or erhn.endswith(dotdomain)):
|
|
|
71928b |
#_debug(" request domain %s does not match cookie domain %s",
|
|
|
71928b |
# req_host, domain)
|
|
|
71928b |
return False
|
|
|
71928b |
diff --git a/Lib/test/test_http_cookiejar.py b/Lib/test/test_http_cookiejar.py
|
|
|
71928b |
index abc625d..6e1b308 100644
|
|
|
71928b |
--- a/Lib/test/test_http_cookiejar.py
|
|
|
71928b |
+++ b/Lib/test/test_http_cookiejar.py
|
|
|
71928b |
@@ -415,6 +415,7 @@ class CookieTests(unittest.TestCase):
|
|
|
71928b |
("http://foo.bar.com/", ".foo.bar.com", True),
|
|
|
71928b |
("http://foo.bar.com/", "foo.bar.com", True),
|
|
|
71928b |
("http://foo.bar.com/", ".bar.com", True),
|
|
|
71928b |
+ ("http://foo.bar.com/", "bar.com", True),
|
|
|
71928b |
("http://foo.bar.com/", "com", True),
|
|
|
71928b |
("http://foo.com/", "rhubarb.foo.com", False),
|
|
|
71928b |
("http://foo.com/", ".foo.com", True),
|
|
|
71928b |
@@ -425,6 +426,8 @@ class CookieTests(unittest.TestCase):
|
|
|
71928b |
("http://foo/", "foo", True),
|
|
|
71928b |
("http://foo/", "foo.local", True),
|
|
|
71928b |
("http://foo/", ".local", True),
|
|
|
71928b |
+ ("http://barfoo.com", ".foo.com", False),
|
|
|
71928b |
+ ("http://barfoo.com", "foo.com", False),
|
|
|
71928b |
]:
|
|
|
71928b |
request = urllib.request.Request(url)
|
|
|
71928b |
r = pol.domain_return_ok(domain, request)
|
|
|
71928b |
@@ -959,6 +962,33 @@ class CookieTests(unittest.TestCase):
|
|
|
71928b |
c.add_cookie_header(req)
|
|
|
71928b |
self.assertFalse(req.has_header("Cookie"))
|
|
|
71928b |
|
|
|
71928b |
+ c.clear()
|
|
|
71928b |
+
|
|
|
71928b |
+ pol.set_blocked_domains([])
|
|
|
71928b |
+ req = urllib.request.Request("http://acme.com/")
|
|
|
71928b |
+ res = FakeResponse(headers, "http://acme.com/")
|
|
|
71928b |
+ cookies = c.make_cookies(res, req)
|
|
|
71928b |
+ c.extract_cookies(res, req)
|
|
|
71928b |
+ self.assertEqual(len(c), 1)
|
|
|
71928b |
+
|
|
|
71928b |
+ req = urllib.request.Request("http://acme.com/")
|
|
|
71928b |
+ c.add_cookie_header(req)
|
|
|
71928b |
+ self.assertTrue(req.has_header("Cookie"))
|
|
|
71928b |
+
|
|
|
71928b |
+ req = urllib.request.Request("http://badacme.com/")
|
|
|
71928b |
+ c.add_cookie_header(req)
|
|
|
71928b |
+ self.assertFalse(pol.return_ok(cookies[0], req))
|
|
|
71928b |
+ self.assertFalse(req.has_header("Cookie"))
|
|
|
71928b |
+
|
|
|
71928b |
+ p = pol.set_blocked_domains(["acme.com"])
|
|
|
71928b |
+ req = urllib.request.Request("http://acme.com/")
|
|
|
71928b |
+ c.add_cookie_header(req)
|
|
|
71928b |
+ self.assertFalse(req.has_header("Cookie"))
|
|
|
71928b |
+
|
|
|
71928b |
+ req = urllib.request.Request("http://badacme.com/")
|
|
|
71928b |
+ c.add_cookie_header(req)
|
|
|
71928b |
+ self.assertFalse(req.has_header("Cookie"))
|
|
|
71928b |
+
|
|
|
71928b |
def test_secure(self):
|
|
|
71928b |
for ns in True, False:
|
|
|
71928b |
for whitespace in " ", "":
|