|
| 1 | +From 753e79fd29bd6242575330d702caa95bc0a9f569 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Kanishk Bansal <kbkanishk975@gmail.com> |
| 3 | +Date: Thu, 6 Feb 2025 18:45:06 +0000 |
| 4 | +Subject: [PATCH] Address CVE-2025-0938 |
| 5 | + |
| 6 | +--- |
| 7 | + Lib/urllib/parse.py | 20 ++++++++++++++++++-- |
| 8 | + 1 file changed, 18 insertions(+), 2 deletions(-) |
| 9 | + |
| 10 | +diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py |
| 11 | +index 2eb3448..dc0b71f 100644 |
| 12 | +--- a/Lib/urllib/parse.py |
| 13 | ++++ b/Lib/urllib/parse.py |
| 14 | +@@ -443,6 +443,23 @@ def _checknetloc(netloc): |
| 15 | + raise ValueError("netloc '" + netloc + "' contains invalid " + |
| 16 | + "characters under NFKC normalization") |
| 17 | + |
| 18 | ++def _check_bracketed_netloc(netloc): |
| 19 | ++ # Note that this function must mirror the splitting |
| 20 | ++ # done in NetlocResultMixins._hostinfo(). |
| 21 | ++ hostname_and_port = netloc.rpartition('@')[2] |
| 22 | ++ before_bracket, have_open_br, bracketed = hostname_and_port.partition('[') |
| 23 | ++ if have_open_br: |
| 24 | ++ # No data is allowed before a bracket. |
| 25 | ++ if before_bracket: |
| 26 | ++ raise ValueError("Invalid IPv6 URL") |
| 27 | ++ hostname, _, port = bracketed.partition(']') |
| 28 | ++ # No data is allowed after the bracket but before the port delimiter. |
| 29 | ++ if port and not port.startswith(":"): |
| 30 | ++ raise ValueError("Invalid IPv6 URL") |
| 31 | ++ else: |
| 32 | ++ hostname, _, port = hostname_and_port.partition(':') |
| 33 | ++ _check_bracketed_host(hostname) |
| 34 | ++ |
| 35 | + # Valid bracketed hosts are defined in |
| 36 | + # https://www.rfc-editor.org/rfc/rfc3986#page-49 and https://url.spec.whatwg.org/ |
| 37 | + def _check_bracketed_host(hostname): |
| 38 | +@@ -506,8 +523,7 @@ def urlsplit(url, scheme='', allow_fragments=True): |
| 39 | + (']' in netloc and '[' not in netloc)): |
| 40 | + raise ValueError("Invalid IPv6 URL") |
| 41 | + if '[' in netloc and ']' in netloc: |
| 42 | +- bracketed_host = netloc.partition('[')[2].partition(']')[0] |
| 43 | +- _check_bracketed_host(bracketed_host) |
| 44 | ++ _check_bracketed_netloc(netloc) |
| 45 | + if allow_fragments and '#' in url: |
| 46 | + url, fragment = url.split('#', 1) |
| 47 | + if '?' in url: |
| 48 | +-- |
| 49 | +2.43.0 |
| 50 | + |
0 commit comments