Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ee15aa2b
Commit
ee15aa2b
authored
Jun 15, 2019
by
Xtreak
Committed by
Serhiy Storchaka
Jun 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.7] bpo-35647: Fix path check in cookiejar. (GH-11436) (GH-13427)
parent
979daae3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
5 deletions
+41
-5
Lib/cookielib.py
Lib/cookielib.py
+9
-5
Lib/test/test_cookielib.py
Lib/test/test_cookielib.py
+29
-0
Misc/NEWS.d/next/Security/2019-05-20-00-49-29.bpo-35647.oWmiGU.rst
....d/next/Security/2019-05-20-00-49-29.bpo-35647.oWmiGU.rst
+3
-0
No files found.
Lib/cookielib.py
View file @
ee15aa2b
...
...
@@ -984,7 +984,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
...
...
@@ -1191,11 +1191,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 = adict.keys()
...
...
Lib/test/test_cookielib.py
View file @
ee15aa2b
...
...
@@ -649,6 +649,35 @@ class CookieTests(TestCase):
req
=
Request
(
"http://www.example.com"
)
self
.
assertEqual
(
request_path
(
req
),
"/"
)
def
test_path_prefix_match
(
self
):
from
cookielib
import
CookieJar
,
DefaultCookiePolicy
from
urllib2
import
Request
pol
=
DefaultCookiePolicy
()
strict_ns_path_pol
=
DefaultCookiePolicy
(
strict_ns_set_path
=
True
)
c
=
CookieJar
(
pol
)
base_url
=
"http://bar.com"
interact_netscape
(
c
,
base_url
,
'spam=eggs; Path=/foo'
)
cookie
=
c
.
_cookies
[
'bar.com'
][
'/foo'
][
'spam'
]
for
path
,
ok
in
[(
'/foo'
,
True
),
(
'/foo/'
,
True
),
(
'/foo/bar'
,
True
),
(
'/'
,
False
),
(
'/foobad/foo'
,
False
)]:
url
=
'{0}{1}'
.
format
(
base_url
,
path
)
req
=
Request
(
url
)
h
=
interact_netscape
(
c
,
url
)
if
ok
:
self
.
assertIn
(
'spam=eggs'
,
h
,
"cookie not set for {0}"
.
format
(
path
))
self
.
assertTrue
(
strict_ns_path_pol
.
set_ok_path
(
cookie
,
req
))
else
:
self
.
assertNotIn
(
'spam=eggs'
,
h
,
"cookie set for {0}"
.
format
(
path
))
self
.
assertFalse
(
strict_ns_path_pol
.
set_ok_path
(
cookie
,
req
))
def
test_request_port
(
self
):
from
urllib2
import
Request
from
cookielib
import
request_port
,
DEFAULT_HTTP_PORT
...
...
Misc/NEWS.d/next/Security/2019-05-20-00-49-29.bpo-35647.oWmiGU.rst
0 → 100644
View file @
ee15aa2b
Don't set cookie for a request when the request path is a prefix match of
the cookie's path attribute but doesn't end with "/". Patch by Karthikeyan
Singaravelan.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment