-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-135768: fix allowed/blocked IPv6 domains in http.cookiejar
#135771
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
e3cfeb6
8c5320a
4c452f9
60304ce
714d4d8
4c9ab02
2c9f6a4
a5198ee
baf62d1
0783fc1
dffb204
056b44d
37c1933
779e443
1c00c39
4c12cec
0cf11d7
88a6af1
d8411c0
7646042
9eb52e3
09f5a61
d440b54
f9aa74f
7f65ca9
a3a93f5
dd04e81
e553fe8
af9d29e
56ac545
f90b354
3d1cc91
0879750
7731e7f
35f8b9e
9c4a91f
1b0f228
8f2c9c3
e01652e
3d59ed9
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 |
---|---|---|
|
@@ -532,15 +532,31 @@ def parse_ns_headers(ns_headers): | |
return result | ||
|
||
|
||
# only kept for backwards compatibilty. | ||
IPV4_RE = re.compile(r"\.\d+$", re.ASCII) | ||
|
||
def is_ip_like(text: str): | ||
"""Return True if text is a valid hostname in the form of IP address.""" | ||
from ipaddress import IPv4Address, IPv6Address | ||
# check for IPv4 address | ||
try: | ||
IPv4Address(text) | ||
except ValueError: | ||
# check for IPv6 address in [] | ||
if text.startswith('[') and text.endswith(']'): | ||
try: | ||
IPv6Address(text.removeprefix('[').removesuffix(']')) | ||
except ValueError: | ||
return False | ||
else: | ||
return False # not a IPv6 address in [] | ||
Comment on lines
+546
to
+552
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. Why are IPv6 addressed not surrounded Try to look at the RFC as well to see if there are more information about IPv6 domains. |
||
return True | ||
def is_HDN(text): | ||
"""Return True if text is a host domain name.""" | ||
# XXX | ||
# This may well be wrong. Which RFC is HDN defined in, if any (for | ||
# the purposes of RFC 2965)? | ||
# For the current implementation, what about IPv6? Remember to look | ||
# at other uses of IPV4_RE also, if change this. | ||
if IPV4_RE.search(text): | ||
if is_ip_like(text): | ||
return False | ||
if text == "": | ||
return False | ||
|
@@ -593,9 +609,7 @@ def liberal_is_HDN(text): | |
For accepting/blocking domains. | ||
|
||
""" | ||
if IPV4_RE.search(text): | ||
return False | ||
return True | ||
return not is_ip_like(text) | ||
|
||
def user_domain_match(A, B): | ||
"""For blocking/accepting domains. | ||
|
@@ -641,7 +655,17 @@ def eff_request_host(request): | |
|
||
""" | ||
erhn = req_host = request_host(request) | ||
if "." not in req_host: | ||
if req_host.startswith('[') and req_host.endswith(']'): | ||
from ipaddress import IPv6Address | ||
try: | ||
IPv6Address(req_host.removeprefix('[').removesuffix(']')) | ||
is_ipV6 = True | ||
except ValueError: | ||
is_ipV6 = False | ||
else: | ||
is_ipV6 = False | ||
if "." not in req_host and not is_ipV6: | ||
# avoid adding .local at the end of a IPV6 address | ||
LamentXU123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
erhn = req_host + ".local" | ||
return req_host, erhn | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:mod:`http.cookiejar`: fix allowed and blocked IPv6 domains | ||
in :class:`~http.cookiejar.DefaultCookiePolicy`. |
Uh oh!
There was an error while loading. Please reload this page.