You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[CVE-2024-11168] urlparse incorrectly retrieves IPv4 and regular name hosts from inside of brackets #103848
As implemented, the URL scheme://foobar.[::1]/ is considered correct, but results in the hostname value of ::1. The hostname portion of the netloc is invalid however, as it doesn't start with [. Shouldn't the parser at least validate that the [ bracket is the first character or directly following a @?
This change caused an issue on our system. We have brackets in a password. Since 3.11.4, urlparse tries to parse an ip address if it finds brackets. The brackets don't even have to be in the correct order.
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"/usr/local/lib/python3.11/urllib/parse.py", line395, inurlparsesplitresult=urlsplit(url, scheme, allow_fragments)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/usr/local/lib/python3.11/urllib/parse.py", line500, inurlsplit_check_bracketed_host(bracketed_host)
File"/usr/local/lib/python3.11/urllib/parse.py", line446, in_check_bracketed_hostip=ipaddress.ip_address(hostname) # Throws Value Error if not IPv6 or IPv4^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/usr/local/lib/python3.11/ipaddress.py", line54, inip_addressraiseValueError(f'{address!r} does not appear to be an IPv4 or IPv6 address')
ValueError: '@host.com'doesnotappeartobeanIPv4orIPv6address
This change caused an issue on our system. We have brackets in a password. Since 3.11.4, urlparse tries to parse an ip address if it finds brackets. The brackets don't even have to be in the correct order.
That this worked before was a bug. urlparse() was violating the various and miriad URL standards before; [ and ] are reserved characters with meaning in the netloc portion of a URL (the part between the scheme:// and /path) and must be URL encoded. See the WhatWG living URL standard percent-encoding section; for the userinfo part (username + password), you need to encode:
U+002F (/), U+003A (:), U+003B (;), U+003D (=), U+0040 (@), U+005B ([) to U+005E (^), inclusive, and U+007C (|).
I'm also hitting "ValueError: 'xxxxx' does not appear to be an IPv4 or IPv6 address" on code that was working.
In my case I have no control over the input data, it's background noise from the internet that i'm parsing and analyzing. Some of the crap in my dataset is very much not standards compliant. None the less, as it was working and now isn't i figured i should 👍 before i start vendoring old versions of the stdlib into my project 😆
My backport of fix for Python 3.6 (which with minimal changes applies to 3.4 as well, and with a lot of changes, including injecting ipaddress from https://github.com/phihag/ipaddress into the Python standard library, into 2.7) is at openSUSE-Python@4f2496b
Hi @mcepl. I'm currently evaluating how to fix this in older Debian dists for 2.7, and FYI it seems the version from OpenSUSE Leap 15 (150000.74.1) doesn't fully fix it:
(expected: ValueError)
It seems CVE-2024-11168-validation-IPv6-addrs.patch fixes the "http://" special case but not the general case (which handles "httpS://"). I didn't check the 3.6 patch closely but it seems it's the opposite situation there.
After fixing the above I also get a couple test_urlparse errors, related to passing non-unicode data to the ipaddress backport. Casting to Unicode ipaddress.ip_address(unicode(hostname)) appears to tame the testsuite.
(expected: ValueError) It seems CVE-2024-11168-validation-IPv6-addrs.patch fixes the "http://" special case but not the general case (which handles "httpS://"). I didn't check the 3.6 patch closely but it seems it's the opposite situation there.
After fixing the above I also get a couple test_urlparse errors, related to passing non-unicode data to the ipaddress backport. Casting to Unicode ipaddress.ip_address(unicode(hostname)) appears to tame the testsuite.
Activity
gh-103848: Adds checks to ensure that bracketed hosts found by urlspl…
pythongh-103848: Adds checks to ensure that bracketed hosts found by …
[3.11] pythongh-103848: Adds checks to ensure that bracketed hosts fo…
[3.11] gh-103848: Adds checks to ensure that bracketed hosts found by…
Merge branch 'main' into fixloadsuperspec
mjpieters commentedon Jun 6, 2023
As implemented, the URL
scheme://foobar.[::1]/is considered correct, but results in thehostnamevalue of::1. The hostname portion of the netloc is invalid however, as it doesn't start with[. Shouldn't the parser at least validate that the[bracket is the first character or directly following a@?MarcoGlauser commentedon Jun 12, 2023
This change caused an issue on our system. We have brackets in a password. Since 3.11.4, urlparse tries to parse an ip address if it finds brackets. The brackets don't even have to be in the correct order.
Running this code:
In 3.11.3 it works as expected:
In 3.11.4 it throws an exception:
mjpieters commentedon Jun 12, 2023
That this worked before was a bug.
urlparse()was violating the various and miriad URL standards before;[and]are reserved characters with meaning in the netloc portion of a URL (the part between thescheme://and/path) and must be URL encoded. See the WhatWG living URL standard percent-encoding section; for the userinfo part (username + password), you need to encode:/), U+003A (:), U+003B (;), U+003D (=), U+0040 (@), U+005B ([) to U+005E (^), inclusive, and U+007C (|).?), U+0060 (`), U+007B ({), and U+007D (}) (path percent-encode set)."), U+0023 (#), U+003C (<), and U+003E (>) (query percent-encode set).~) (C0 control percent-encode set)So this works:
The password is still URL encoded, use
urllib.parse.unquote()for that.Further references:
MarcoGlauser commentedon Jun 12, 2023
Thank you for the clarification! This makes a lot of sense :)
Handle urlparse ValueError on invalid IP addresses in python >= 3.11
Jc2k commentedon Jun 28, 2023
I'm also hitting "ValueError: 'xxxxx' does not appear to be an IPv4 or IPv6 address" on code that was working.
In my case I have no control over the input data, it's background noise from the internet that i'm parsing and analyzing. Some of the crap in my dataset is very much not standards compliant. None the less, as it was working and now isn't i figured i should 👍 before i start vendoring old versions of the stdlib into my project 😆
tests: Use valid IPv6 address
21 remaining items
test_url.py: handle 3.9 and 3.10 for http://[2a01:5cc0:1:2:3:4] testcase
test_url.py: handle 3.9 and 3.10 for http://[2a01:5cc0:1:2:3:4] testcase
test_url.py: handle 3.9 and 3.10 for http://[2a01:5cc0:1:2:3:4] testcase
test_url.py: handle 3.9 and 3.10 for http://[2a01:5cc0:1:2:3:4] testcase
python3.pkgs.w3lib: fix build with python 3.9 and 3.10
python3.pkgs.w3lib: fix build with python 3.9 and 3.10
Beuc commentedon Mar 7, 2025
Hi @mcepl. I'm currently evaluating how to fix this in older Debian dists for 2.7, and FYI it seems the version from OpenSUSE Leap 15 (150000.74.1) doesn't fully fix it:
(expected: ValueError)
It seems
CVE-2024-11168-validation-IPv6-addrs.patchfixes the "http://" special case but not the general case (which handles "httpS://"). I didn't check the 3.6 patch closely but it seems it's the opposite situation there.After fixing the above I also get a couple test_urlparse errors, related to passing non-unicode data to the ipaddress backport. Casting to Unicode
ipaddress.ip_address(unicode(hostname))appears to tame the testsuite.mcepl commentedon Mar 8, 2025
Do you have a corrected patch? I am all ears!
Beuc commentedon Mar 8, 2025
Now yes :)
OpenSUSE patch with corrections: https://salsa.debian.org/lts-team/packages/python2.7/-/blob/08639c6a31c4726e2862d2908a8a805be9c186df/debian/patches/CVE-2024-11168-opensuse.patch
Alternate approach, without embedding (and having to maintain) ipaddress: https://salsa.debian.org/lts-team/packages/python2.7/-/blob/c62e4e05f86c0e14ae6aa405382268d3c97137c6/debian/patches/CVE-2024-11168.patch
mcepl commentedon Mar 13, 2025
[3.11] pythongh-103848: Adds checks to ensure that bracketed hosts fo…
00444: Security fix for CVE-2024-11168
00444: Security fix for CVE-2024-11168
00444: Security fix for CVE-2024-11168
00444: Security fix for CVE-2024-11168