diff --git a/pkgs/development/interpreters/python/cpython/CVE-2025-0938.patch b/pkgs/development/interpreters/python/cpython/CVE-2025-0938.patch new file mode 100644 index 0000000000000..48800686ab694 --- /dev/null +++ b/pkgs/development/interpreters/python/cpython/CVE-2025-0938.patch @@ -0,0 +1,38 @@ +diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py +index c412c729852272..9d51f4c6812b57 100644 +--- a/Lib/urllib/parse.py ++++ b/Lib/urllib/parse.py +@@ -439,6 +439,23 @@ def _checknetloc(netloc): + raise ValueError("netloc '" + netloc + "' contains invalid " + + "characters under NFKC normalization") + ++def _check_bracketed_netloc(netloc): ++ # Note that this function must mirror the splitting ++ # done in NetlocResultMixins._hostinfo(). ++ hostname_and_port = netloc.rpartition('@')[2] ++ before_bracket, have_open_br, bracketed = hostname_and_port.partition('[') ++ if have_open_br: ++ # No data is allowed before a bracket. ++ if before_bracket: ++ raise ValueError("Invalid IPv6 URL") ++ hostname, _, port = bracketed.partition(']') ++ # No data is allowed after the bracket but before the port delimiter. ++ if port and not port.startswith(":"): ++ raise ValueError("Invalid IPv6 URL") ++ else: ++ hostname, _, port = hostname_and_port.partition(':') ++ _check_bracketed_host(hostname) ++ + # Valid bracketed hosts are defined in + # https://www.rfc-editor.org/rfc/rfc3986#page-49 and https://url.spec.whatwg.org/ + def _check_bracketed_host(hostname): +@@ -505,8 +522,7 @@ def _urlsplit(url, scheme=None, allow_fragments=True): + (']' in netloc and '[' not in netloc)): + raise ValueError("Invalid IPv6 URL") + if '[' in netloc and ']' in netloc: +- bracketed_host = netloc.partition('[')[2].partition(']')[0] +- _check_bracketed_host(bracketed_host) ++ _check_bracketed_netloc(netloc) + if allow_fragments and '#' in url: + url, fragment = url.split('#', 1) + if '?' in url: diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index d0cb05268d43f..c1b2af3589e88 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -252,6 +252,7 @@ in with passthru; stdenv.mkDerivation (finalAttrs: { # (since it will do a futile invocation of gcc (!) to find # libuuid, slowing down program startup a lot). noldconfigPatch + ./CVE-2025-0938.patch ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.isFreeBSD) [ # Cross compilation only supports a limited number of "known good" # configurations. If you're reading this and it's been a long time