A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/cpython/commit/97c7d78fda49e03fc773c171ce0c736d02bb73f5 below:

Fix path check in cookiejar (GH-11436) · python/cpython@97c7d78 · GitHub

File tree Expand file treeCollapse file tree 3 files changed

+36

-5

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+36

-5

lines changed Original file line number Diff line number Diff line change

@@ -990,7 +990,7 @@ def set_ok_path(self, cookie, request):

990 990

req_path = request_path(request)

991 991

if ((cookie.version > 0 or

992 992

(cookie.version == 0 and self.strict_ns_set_path)) and

993 -

not req_path.startswith(cookie.path)):

993 +

not self.path_return_ok(cookie.path, request)):

994 994

_debug(" path attribute %s is not a prefix of request "

995 995

"path %s", cookie.path, req_path)

996 996

return False

@@ -1197,11 +1197,15 @@ def domain_return_ok(self, domain, request):

1197 1197

def path_return_ok(self, path, request):

1198 1198

_debug("- checking cookie path=%s", path)

1199 1199

req_path = request_path(request)

1200 -

if not req_path.startswith(path):

1201 -

_debug(" %s does not path-match %s", req_path, path)

1202 -

return False

1203 -

return True

1200 +

pathlen = len(path)

1201 +

if req_path == path:

1202 +

return True

1203 +

elif (req_path.startswith(path) and

1204 +

(path.endswith("/") or req_path[pathlen:pathlen+1] == "/")):

1205 +

return True

1204 1206 1207 +

_debug(" %s does not path-match %s", req_path, path)

1208 +

return False

1205 1209 1206 1210

def vals_sorted_by_key(adict):

1207 1211

keys = sorted(adict.keys())

Original file line number Diff line number Diff line change

@@ -695,6 +695,30 @@ def test_request_path(self):

695 695

req = urllib.request.Request("http://www.example.com")

696 696

self.assertEqual(request_path(req), "/")

697 697 698 +

def test_path_prefix_match(self):

699 +

pol = DefaultCookiePolicy()

700 +

strict_ns_path_pol = DefaultCookiePolicy(strict_ns_set_path=True)

701 + 702 +

c = CookieJar(pol)

703 +

base_url = "http://bar.com"

704 +

interact_netscape(c, base_url, 'spam=eggs; Path=/foo')

705 +

cookie = c._cookies['bar.com']['/foo']['spam']

706 + 707 +

for path, ok in [('/foo', True),

708 +

('/foo/', True),

709 +

('/foo/bar', True),

710 +

('/', False),

711 +

('/foobad/foo', False)]:

712 +

url = f'{base_url}{path}'

713 +

req = urllib.request.Request(url)

714 +

h = interact_netscape(c, url)

715 +

if ok:

716 +

self.assertIn('spam=eggs', h, f"cookie not set for {path}")

717 +

self.assertTrue(strict_ns_path_pol.set_ok_path(cookie, req))

718 +

else:

719 +

self.assertNotIn('spam=eggs', h, f"cookie set for {path}")

720 +

self.assertFalse(strict_ns_path_pol.set_ok_path(cookie, req))

721 + 698 722

def test_request_port(self):

699 723

req = urllib.request.Request("http://www.acme.com:1234/",

700 724

headers={"Host": "www.acme.com:4321"})

Original file line number Diff line number Diff line change

@@ -0,0 +1,3 @@

1 +

Don't set cookie for a request when the request path is a prefix match of

2 +

the cookie's path attribute but doesn't end with "/". Patch by Karthikeyan

3 +

Singaravelan.

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4