Skip to content

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

Open
wants to merge 62 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
e3cfeb6
Update cookiejar.py
LamentXU123 Jun 20, 2025
8c5320a
📜🤖 Added by blurb_it.
blurb-it[bot] Jun 20, 2025
4c452f9
Update 2025-06-20-17-03-51.gh-issue-135768.DhUJWf.rst
LamentXU123 Jun 20, 2025
60304ce
Update 2025-06-20-17-03-51.gh-issue-135768.DhUJWf.rst
LamentXU123 Jun 20, 2025
714d4d8
Update 2025-06-20-17-03-51.gh-issue-135768.DhUJWf.rst
LamentXU123 Jun 20, 2025
4c9ab02
Update Lib/http/cookiejar.py
LamentXU123 Jun 20, 2025
2c9f6a4
Update Lib/http/cookiejar.py
LamentXU123 Jun 20, 2025
a5198ee
Update Lib/http/cookiejar.py
LamentXU123 Jun 20, 2025
baf62d1
Update Lib/http/cookiejar.py
LamentXU123 Jun 20, 2025
0783fc1
Update cookiejar.py
LamentXU123 Jun 20, 2025
dffb204
add IPV6 regex
LamentXU123 Jun 20, 2025
056b44d
Update Misc/NEWS.d/next/Library/2025-06-20-17-03-51.gh-issue-135768.D…
LamentXU123 Jun 20, 2025
37c1933
add string method instead of regex to detect IPV6
LamentXU123 Jun 20, 2025
779e443
update is_ip
LamentXU123 Jun 20, 2025
1c00c39
update comments
LamentXU123 Jun 20, 2025
4c12cec
Update test_http_cookiejar.py
LamentXU123 Jun 20, 2025
0cf11d7
Update Lib/http/cookiejar.py
LamentXU123 Jun 21, 2025
88a6af1
Update Lib/http/cookiejar.py
LamentXU123 Jun 21, 2025
d8411c0
Update cookiejar.py
LamentXU123 Jun 21, 2025
7646042
more test added
LamentXU123 Jun 21, 2025
9eb52e3
Update test_http_cookiejar.py
LamentXU123 Jun 21, 2025
09f5a61
Update test_http_cookiejar.py
LamentXU123 Jun 21, 2025
d440b54
Update test_http_cookiejar.py
LamentXU123 Jun 21, 2025
f9aa74f
Update test_http_cookiejar.py
LamentXU123 Jun 21, 2025
7f65ca9
Update test_http_cookiejar.py
LamentXU123 Jun 21, 2025
a3a93f5
Merge branch 'main' into support-IPv6-in-cookiejar
LamentXU123 Jun 21, 2025
dd04e81
Update test_http_cookiejar.py
LamentXU123 Jun 21, 2025
e553fe8
Update Lib/http/cookiejar.py
LamentXU123 Jun 21, 2025
af9d29e
Update Lib/test/test_http_cookiejar.py
LamentXU123 Jun 21, 2025
56ac545
Update cookiejar.py
LamentXU123 Jun 21, 2025
f90b354
Update test_http_cookiejar.py
LamentXU123 Jun 21, 2025
3d1cc91
Update cookiejar.py
LamentXU123 Jun 21, 2025
0879750
update is_ip
LamentXU123 Jun 21, 2025
7731e7f
delete test for ::1
LamentXU123 Jun 21, 2025
35f8b9e
Merge branch 'main' into support-IPv6-in-cookiejar
LamentXU123 Jun 21, 2025
9c4a91f
Update test_http_cookiejar.py
LamentXU123 Jun 21, 2025
1b0f228
Update test_http_cookiejar.py
LamentXU123 Jun 21, 2025
8f2c9c3
Change is_ip to is_ip_like
LamentXU123 Jun 21, 2025
e01652e
Update test script for is_ip_like
LamentXU123 Jun 21, 2025
3d59ed9
Update cookiejar.py
LamentXU123 Jun 21, 2025
befc9e2
Update test_http_cookiejar.py
LamentXU123 Jun 22, 2025
57fca8b
Update cookiejar.py
LamentXU123 Jun 22, 2025
abb4320
Update Lib/test/test_http_cookiejar.py
LamentXU123 Jun 22, 2025
2aac70f
Update Lib/http/cookiejar.py
LamentXU123 Jun 22, 2025
3b9620c
Update Lib/http/cookiejar.py
LamentXU123 Jun 22, 2025
267d499
Update Lib/http/cookiejar.py
LamentXU123 Jun 22, 2025
a875311
Update Lib/http/cookiejar.py
LamentXU123 Jun 22, 2025
720c80f
add false test for ::1
LamentXU123 Jun 22, 2025
2f90ecd
Update cookiejar.py
LamentXU123 Jun 22, 2025
c37042c
Update cookiejar.py
LamentXU123 Jun 22, 2025
7b6feea
Update cookiejar.py
LamentXU123 Jun 22, 2025
1fd504b
Update cookiejar.py
LamentXU123 Jun 22, 2025
6238901
Update cookiejar.py
LamentXU123 Jun 22, 2025
aef5edf
Update Lib/http/cookiejar.py
LamentXU123 Jun 22, 2025
c5a1be2
Update Lib/http/cookiejar.py
LamentXU123 Jun 22, 2025
e3b6a1c
Update cookiejar.py
LamentXU123 Jun 22, 2025
e37015c
Update Lib/http/cookiejar.py
LamentXU123 Jun 22, 2025
36cb03b
Update Lib/http/cookiejar.py
LamentXU123 Jun 22, 2025
6fe7c76
Merge branch 'main' into support-IPv6-in-cookiejar
LamentXU123 Jun 22, 2025
e7e1d83
Update Lib/http/cookiejar.py
LamentXU123 Jun 22, 2025
3cea83c
Merge branch 'main' into support-IPv6-in-cookiejar
LamentXU123 Jun 23, 2025
1ab21ea
Update ACKS
LamentXU123 Jun 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions Lib/http/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,20 @@ def parse_ns_headers(ns_headers):


IPV4_RE = re.compile(r"\.\d+$", re.ASCII)
def is_ip(text):
"""Return True if text is a valid IP address."""
from ipaddress import ip_address
try:
ip_address(text)
except ValueError:
return False
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(text):
return False
if text == "":
return False
Expand Down Expand Up @@ -593,9 +599,7 @@ def liberal_is_HDN(text):
For accepting/blocking domains.

"""
if IPV4_RE.search(text):
return False
return True
return not is_ip(text)

def user_domain_match(A, B):
"""For blocking/accepting domains.
Expand All @@ -607,7 +611,6 @@ def user_domain_match(A, B):
B = B.lower()
if not (liberal_is_HDN(A) and liberal_is_HDN(B)):
if A == B:
# equal IP addresses
return True
return False
initial_dot = B.startswith(".")
Expand Down Expand Up @@ -641,7 +644,8 @@ def eff_request_host(request):

"""
erhn = req_host = request_host(request)
if "." not in req_host:
if "." not in req_host and '[' not in req_host:
# detect '[' mainly for IPv6 addr like [::1]
erhn = req_host + ".local"
return req_host, erhn

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:mod:`http.cookiejar` now supports IPv6 address in blocked_domains and allowed_domains of class DefaultCookiePolicy
Loading