diff --git a/SOURCES/00399-CVE-2023-24329.patch b/SOURCES/00399-CVE-2023-24329.patch new file mode 100644 index 0000000..81b22d1 --- /dev/null +++ b/SOURCES/00399-CVE-2023-24329.patch @@ -0,0 +1,126 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lumir Balhar +Date: Thu, 25 May 2023 10:03:57 +0200 +Subject: [PATCH] 00399: gh-102153: Start stripping C0 control and space chars + in `urlsplit` (GH-102508) (#104575) + +* gh-102153: Start stripping C0 control and space chars in `urlsplit` (GH-102508) + +`urllib.parse.urlsplit` has already been respecting the WHATWG spec a bit GH-25595. + +This adds more sanitizing to respect the "Remove any leading C0 control or space from input" [rule](https://url.spec.whatwg.org/GH-url-parsing:~:text=Remove%20any%20leading%20and%20trailing%20C0%20control%20or%20space%20from%20input.) in response to [CVE-2023-24329](https://nvd.nist.gov/vuln/detail/CVE-2023-24329). + +Backported to Python 2 from Python 3.12. + +Co-authored-by: Illia Volochii +Co-authored-by: Gregory P. Smith [Google] +Co-authored-by: Lumir Balhar +--- + Lib/test/test_urlparse.py | 57 +++++++++++++++++++++++++++++++++++++++ + Lib/urlparse.py | 10 +++++++ + 2 files changed, 67 insertions(+) + +diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py +index 16eefed56f6..419e9c2bdcc 100644 +--- a/Lib/test/test_urlparse.py ++++ b/Lib/test/test_urlparse.py +@@ -666,7 +666,64 @@ class UrlParseTestCase(unittest.TestCase): + self.assertEqual(p.scheme, "https") + self.assertEqual(p.geturl(), "https://www.python.org/javascript:alert('msg')/?query=something#fragment") + ++ def test_urlsplit_strip_url(self): ++ noise = "".join([chr(i) for i in range(0, 0x20 + 1)]) ++ base_url = "http://User:Pass@www.python.org:080/doc/?query=yes#frag" + ++ url = noise.decode("utf-8") + base_url ++ p = urlparse.urlsplit(url) ++ self.assertEqual(p.scheme, "http") ++ self.assertEqual(p.netloc, "User:Pass@www.python.org:080") ++ self.assertEqual(p.path, "/doc/") ++ self.assertEqual(p.query, "query=yes") ++ self.assertEqual(p.fragment, "frag") ++ self.assertEqual(p.username, "User") ++ self.assertEqual(p.password, "Pass") ++ self.assertEqual(p.hostname, "www.python.org") ++ self.assertEqual(p.port, 80) ++ self.assertEqual(p.geturl(), base_url) ++ ++ url = noise + base_url.encode("utf-8") ++ p = urlparse.urlsplit(url) ++ self.assertEqual(p.scheme, b"http") ++ self.assertEqual(p.netloc, b"User:Pass@www.python.org:080") ++ self.assertEqual(p.path, b"/doc/") ++ self.assertEqual(p.query, b"query=yes") ++ self.assertEqual(p.fragment, b"frag") ++ self.assertEqual(p.username, b"User") ++ self.assertEqual(p.password, b"Pass") ++ self.assertEqual(p.hostname, b"www.python.org") ++ self.assertEqual(p.port, 80) ++ self.assertEqual(p.geturl(), base_url.encode("utf-8")) ++ ++ # Test that trailing space is preserved as some applications rely on ++ # this within query strings. ++ query_spaces_url = "https://www.python.org:88/doc/?query= " ++ p = urlparse.urlsplit(noise.decode("utf-8") + query_spaces_url) ++ self.assertEqual(p.scheme, "https") ++ self.assertEqual(p.netloc, "www.python.org:88") ++ self.assertEqual(p.path, "/doc/") ++ self.assertEqual(p.query, "query= ") ++ self.assertEqual(p.port, 88) ++ self.assertEqual(p.geturl(), query_spaces_url) ++ ++ p = urlparse.urlsplit("www.pypi.org ") ++ # That "hostname" gets considered a "path" due to the ++ # trailing space and our existing logic... YUCK... ++ # and re-assembles via geturl aka unurlsplit into the original. ++ # django.core.validators.URLValidator (at least through v3.2) relies on ++ # this, for better or worse, to catch it in a ValidationError via its ++ # regular expressions. ++ # Here we test the basic round trip concept of such a trailing space. ++ self.assertEqual(urlparse.urlunsplit(p), "www.pypi.org ") ++ ++ # with scheme as cache-key ++ url = "//www.python.org/" ++ scheme = noise.decode("utf-8") + "https" + noise.decode("utf-8") ++ for _ in range(2): ++ p = urlparse.urlsplit(url, scheme=scheme) ++ self.assertEqual(p.scheme, "https") ++ self.assertEqual(p.geturl(), "https://www.python.org/") + + def test_attributes_bad_port(self): + """Check handling of non-integer ports.""" +diff --git a/Lib/urlparse.py b/Lib/urlparse.py +index 6cc40a8d2fb..0f03a7cc4a9 100644 +--- a/Lib/urlparse.py ++++ b/Lib/urlparse.py +@@ -26,6 +26,10 @@ scenarios for parsing, and for backward compatibility purposes, some + parsing quirks from older RFCs are retained. The testcases in + test_urlparse.py provides a good indicator of parsing behavior. + ++The WHATWG URL Parser spec should also be considered. We are not compliant with ++it either due to existing user code API behavior expectations (Hyrum's Law). ++It serves as a useful guide when making changes. ++ + """ + + import re +@@ -63,6 +67,10 @@ scheme_chars = ('abcdefghijklmnopqrstuvwxyz' + '0123456789' + '+-.') + ++# Leading and trailing C0 control and space to be stripped per WHATWG spec. ++# == "".join([chr(i) for i in range(0, 0x20 + 1)]) ++_WHATWG_C0_CONTROL_OR_SPACE = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f ' ++ + # Unsafe bytes to be removed per WHATWG spec + _UNSAFE_URL_BYTES_TO_REMOVE = ['\t', '\r', '\n'] + +@@ -201,6 +209,8 @@ def urlsplit(url, scheme='', allow_fragments=True): + (e.g. netloc is a single string) and we don't expand % escapes.""" + url = _remove_unsafe_bytes_from_url(url) + scheme = _remove_unsafe_bytes_from_url(scheme) ++ url = url.lstrip(_WHATWG_C0_CONTROL_OR_SPACE) ++ scheme = scheme.strip(_WHATWG_C0_CONTROL_OR_SPACE) + allow_fragments = bool(allow_fragments) + key = url, scheme, allow_fragments, type(url), type(scheme) + cached = _parse_cache.get(key, None) diff --git a/SOURCES/99999-python-2.7.5-issues-17979-17998.patch b/SOURCES/99999-python-2.7.5-issues-17979-17998.patch deleted file mode 100644 index fbf2388..0000000 --- a/SOURCES/99999-python-2.7.5-issues-17979-17998.patch +++ /dev/null @@ -1,129 +0,0 @@ - -# HG changeset patch -# User Serhiy Storchaka -# Date 1369166013 -10800 -# Node ID 8408eed151ebee1c546414f1f40be46c1ad76077 -# Parent 7fce9186accb10122e45d975f4b380c2ed0fae35 -Issue #17979: Fixed the re module in build with --disable-unicode. - -diff --git a/Modules/sre.h b/Modules/sre.h ---- a/Modules/sre.h -+++ b/Modules/sre.h -@@ -23,8 +23,8 @@ - # define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX + 1u) - # endif - #else --# define SRE_CODE unsigned long --# if SIZEOF_SIZE_T > SIZEOF_LONG -+# define SRE_CODE unsigned int -+# if SIZEOF_SIZE_T > SIZEOF_INT - # define SRE_MAXREPEAT (~(SRE_CODE)0) - # else - # define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX + 1u) - - -# HG changeset patch -# User Serhiy Storchaka -# Date 1375547193 -10800 -# Node ID e5e425fd1e4f7e859abdced43621203cdfa87a16 -# Parent 8205e72b5cfcdb7a3450c80f3368eff610bc650c -Issue #17998: Fix an internal error in regular expression engine. - -diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py ---- a/Lib/test/test_re.py -+++ b/Lib/test/test_re.py -@@ -907,6 +907,16 @@ class ReTests(unittest.TestCase): - self.assertEqual(m.group(1), "") - self.assertEqual(m.group(2), "y") - -+ def test_issue17998(self): -+ for reps in '*', '+', '?', '{1}': -+ for mod in '', '?': -+ pattern = '.' + reps + mod + 'yz' -+ self.assertEqual(re.compile(pattern, re.S).findall('xyz'), -+ ['xyz'], msg=pattern) -+ pattern = pattern.encode() -+ self.assertEqual(re.compile(pattern, re.S).findall(b'xyz'), -+ [b'xyz'], msg=pattern) -+ - - - def run_re_tests(): -diff --git a/Modules/_sre.c b/Modules/_sre.c ---- a/Modules/_sre.c -+++ b/Modules/_sre.c -@@ -1028,7 +1028,7 @@ entrance: - TRACE(("|%p|%p|REPEAT_ONE %d %d\n", ctx->pattern, ctx->ptr, - ctx->pattern[1], ctx->pattern[2])); - -- if (ctx->pattern[1] > end - ctx->ptr) -+ if ((Py_ssize_t) ctx->pattern[1] > end - ctx->ptr) - RETURN_FAILURE; /* cannot match */ - - state->ptr = ctx->ptr; -@@ -1111,7 +1111,7 @@ entrance: - TRACE(("|%p|%p|MIN_REPEAT_ONE %d %d\n", ctx->pattern, ctx->ptr, - ctx->pattern[1], ctx->pattern[2])); - -- if (ctx->pattern[1] > end - ctx->ptr) -+ if ((Py_ssize_t) ctx->pattern[1] > end - ctx->ptr) - RETURN_FAILURE; /* cannot match */ - - state->ptr = ctx->ptr; -@@ -1210,7 +1210,7 @@ entrance: - TRACE(("|%p|%p|MAX_UNTIL %d\n", ctx->pattern, - ctx->ptr, ctx->count)); - -- if (ctx->count < ctx->u.rep->pattern[1]) { -+ if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) { - /* not enough matches */ - ctx->u.rep->count = ctx->count; - DO_JUMP(JUMP_MAX_UNTIL_1, jump_max_until_1, -@@ -1224,7 +1224,7 @@ entrance: - RETURN_FAILURE; - } - -- if ((ctx->count < ctx->u.rep->pattern[2] || -+ if ((ctx->count < (Py_ssize_t) ctx->u.rep->pattern[2] || - ctx->u.rep->pattern[2] == SRE_MAXREPEAT) && - state->ptr != ctx->u.rep->last_ptr) { - /* we may have enough matches, but if we can -@@ -1273,7 +1273,7 @@ entrance: - TRACE(("|%p|%p|MIN_UNTIL %d %p\n", ctx->pattern, - ctx->ptr, ctx->count, ctx->u.rep->pattern)); - -- if (ctx->count < ctx->u.rep->pattern[1]) { -+ if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) { - /* not enough matches */ - ctx->u.rep->count = ctx->count; - DO_JUMP(JUMP_MIN_UNTIL_1, jump_min_until_1, -@@ -1302,7 +1302,7 @@ entrance: - - LASTMARK_RESTORE(); - -- if ((ctx->count >= ctx->u.rep->pattern[2] -+ if ((ctx->count >= (Py_ssize_t) ctx->u.rep->pattern[2] - && ctx->u.rep->pattern[2] != SRE_MAXREPEAT) || - state->ptr == ctx->u.rep->last_ptr) - RETURN_FAILURE; -diff --git a/Modules/sre.h b/Modules/sre.h ---- a/Modules/sre.h -+++ b/Modules/sre.h -@@ -20,14 +20,14 @@ - # if SIZEOF_SIZE_T > 4 - # define SRE_MAXREPEAT (~(SRE_CODE)0) - # else --# define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX + 1u) -+# define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX) - # endif - #else - # define SRE_CODE unsigned int - # if SIZEOF_SIZE_T > SIZEOF_INT - # define SRE_MAXREPEAT (~(SRE_CODE)0) - # else --# define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX + 1u) -+# define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX) - # endif - #endif - - diff --git a/SPECS/python.spec b/SPECS/python.spec index b42e7ff..4f649fe 100644 --- a/SPECS/python.spec +++ b/SPECS/python.spec @@ -114,7 +114,7 @@ Summary: An interpreted, interactive, object-oriented programming language Name: %{python} # Remember to also rebase python-docs when changing this: Version: 2.7.5 -Release: 92%{?dist} +Release: 93%{?dist} License: Python Group: Development/Languages Requires: %{python}-libs%{?_isa} = %{version}-%{release} @@ -1389,6 +1389,18 @@ Patch378: 00378-support-expat-2-4-5.patch # https://github.com/python/cpython/commit/49d65958e13db03b9a4240d8bdaff1a4be69a1d7 Patch380: 00380-update-test-certs.patch +# 00399 # +# gh-102153: Start stripping C0 control and space chars in `urlsplit` (GH-102508) (#104575) +# +# * gh-102153: Start stripping C0 control and space chars in `urlsplit` (GH-102508) +# +# `urllib.parse.urlsplit` has already been respecting the WHATWG spec a bit GH-25595. +# +# This adds more sanitizing to respect the "Remove any leading C0 control or space from input" [rule](https://url.spec.whatwg.org/GH-url-parsing:~:text=Remove%%20any%%20leading%%20and%%20trailing%%20C0%%20control%%20or%%20space%%20from%%20input.) in response to [CVE-2023-24329](https://nvd.nist.gov/vuln/detail/CVE-2023-24329). +# +# Backported to Python 2 from Python 3.12. +Patch399: 00399-CVE-2023-24329.patch + # (New patches go here ^^^) # # When adding new patches to "python" and "python3" in Fedora 17 onwards, @@ -1414,8 +1426,6 @@ Patch380: 00380-update-test-certs.patch # above: Patch5000: 05000-autotool-intermediates.patch -Patch99999: 99999-python-2.7.5-issues-17979-17998.patch - # ====================================================== # Additional metadata, and subpackages # ====================================================== @@ -1843,10 +1853,8 @@ mv Modules/cryptmodule.c Modules/_cryptmodule.c %patch377 -p1 %patch378 -p1 %patch380 -p1 +%patch399 -p1 -%ifarch %{arm} %{ix86} ppc -%patch99999 -p1 -%endif # Patch 351 adds binary file for testing. We need to apply it using Git. git apply %{PATCH351} @@ -2722,6 +2730,10 @@ rm -fr %{buildroot} # ====================================================== %changelog +* Thu May 25 2023 Lumír Balhar - 2.7.5-93 +- Fix for CVE-2023-24329 +Resolves: rhbz#2173917 + * Tue May 24 2022 Charalampos Stratakis - 2.7.5-92 - Security fix for CVE-2021-3177 Resolves: rhbz#1918168