summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-03-12 04:28:39 (GMT)
committerNed Deily <nad@python.org>2019-03-12 04:28:39 (GMT)
commit5565b1db6f37f244890369e0d68a3e906aca28b9 (patch)
tree26f2951bc88c1b36b7cedaa0680f099b4d0314a0 /Lib/http
parentb241af861b37e20ad30533bc0b7e2e5491cc470f (diff)
downloadcpython-5565b1db6f37f244890369e0d68a3e906aca28b9.zip
cpython-5565b1db6f37f244890369e0d68a3e906aca28b9.tar.gz
cpython-5565b1db6f37f244890369e0d68a3e906aca28b9.tar.bz2
bpo-35647: Fix path check in cookiejar (GH-11436) (GH-12268)
Co-authored-by: Xtreak <tir.karthi@gmail.com>
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/cookiejar.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py
index 97599d4..e46514b 100644
--- a/Lib/http/cookiejar.py
+++ b/Lib/http/cookiejar.py
@@ -993,7 +993,7 @@ class DefaultCookiePolicy(CookiePolicy):
req_path = request_path(request)
if ((cookie.version > 0 or
(cookie.version == 0 and self.strict_ns_set_path)) and
- not req_path.startswith(cookie.path)):
+ not self.path_return_ok(cookie.path, request)):
_debug(" path attribute %s is not a prefix of request "
"path %s", cookie.path, req_path)
return False
@@ -1200,11 +1200,15 @@ class DefaultCookiePolicy(CookiePolicy):
def path_return_ok(self, path, request):
_debug("- checking cookie path=%s", path)
req_path = request_path(request)
- if not req_path.startswith(path):
- _debug(" %s does not path-match %s", req_path, path)
- return False
- return True
+ pathlen = len(path)
+ if req_path == path:
+ return True
+ elif (req_path.startswith(path) and
+ (path.endswith("/") or req_path[pathlen:pathlen+1] == "/")):
+ return True
+ _debug(" %s does not path-match %s", req_path, path)
+ return False
def vals_sorted_by_key(adict):
keys = sorted(adict.keys())