-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
gh-135993: Fix IPv6 bug in set_ok_port
and return_ok_port
#136076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8680fa4
b911f1e
c69a050
b55a920
f129053
48064f2
e1fe548
f6859dd
05597f8
c5ca056
854422d
428096f
312f66f
94bb9ab
24eb5d9
0415d3f
357b9d1
1034647
9d75634
b7e859f
b7d6e4e
d197796
bc8bad0
7e3237a
cdda526
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -656,16 +656,15 @@ def request_path(request): | |
return path | ||
|
||
def request_port(request): | ||
host = request.host | ||
i = host.find(':') | ||
if i >= 0: | ||
port = host[i+1:] | ||
try: | ||
int(port) | ||
except ValueError: | ||
_debug("nonnumeric port: '%s'", port) | ||
return None | ||
match = cut_port_re.search(request.host) | ||
if match: | ||
port = match[0].removeprefix(':') | ||
else: | ||
i = request.host.rfind(':') | ||
if (i >= 0 | ||
and not ']' in request.host[i+1:] | ||
and not request.host.startswith('[')): # to prevent IPv6 addresses | ||
_debug("nonnumeric port: '%s'", request.host[i+1:]) | ||
port = DEFAULT_HTTP_PORT | ||
return port | ||
|
||
|
@@ -1075,11 +1074,7 @@ def set_ok_domain(self, cookie, request): | |
|
||
def set_ok_port(self, cookie, request): | ||
if cookie.port_specified: | ||
req_port = request_port(request) | ||
if req_port is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remove this also, since Note: In fact the original code here is also wrong. the req_port should be DEFAULT_HTTP_PORT instead of 80. nvm, we just remove this logic. |
||
req_port = "80" | ||
else: | ||
req_port = str(req_port) | ||
req_port = str(request_port(request)) | ||
for p in cookie.port.split(","): | ||
try: | ||
int(p) | ||
|
@@ -1148,8 +1143,6 @@ def return_ok_expires(self, cookie, request): | |
def return_ok_port(self, cookie, request): | ||
if cookie.port: | ||
req_port = request_port(request) | ||
if req_port is None: | ||
req_port = "80" | ||
for p in cookie.port.split(","): | ||
if p == req_port: | ||
break | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:mod:`http.cookiejar`: Fix a bug that occurs when :class:`~http.cookiejar.DefaultCookiePolicy` | ||
attempts to parse the port of an IPv6 address in func ``request_port()``. Patch by Weilin Du. |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is added to print debug message in the original code. ValueError is no longer to be raised, but we still need debug message here.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm adding stricter check to this. There may be case like
www.acme.com:1]34
, and1]34
is not a normal port and needs debug message, so I think I would add a check that the host name must starts with[