summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/python/python3/CVE-2024-7592.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/python/python3/CVE-2024-7592.patch')
-rw-r--r--meta/recipes-devtools/python/python3/CVE-2024-7592.patch140
1 files changed, 0 insertions, 140 deletions
diff --git a/meta/recipes-devtools/python/python3/CVE-2024-7592.patch b/meta/recipes-devtools/python/python3/CVE-2024-7592.patch
deleted file mode 100644
index 7303a41e20..0000000000
--- a/meta/recipes-devtools/python/python3/CVE-2024-7592.patch
+++ /dev/null
@@ -1,140 +0,0 @@
1From 3c15b8437f57fe1027171b34af88bf791cf1868c Mon Sep 17 00:00:00 2001
2From: "Miss Islington (bot)"
3 <31488909+miss-islington@users.noreply.github.com>
4Date: Wed, 4 Sep 2024 17:50:36 +0200
5Subject: [PATCH 1/2] [3.10] gh-123067: Fix quadratic complexity in parsing
6 "-quoted cookie values with backslashes (GH-123075) (#123106)
7
8This fixes CVE-2024-7592.
9(cherry picked from commit 44e458357fca05ca0ae2658d62c8c595b048b5ef)
10
11Upstream-Status: Backport from https://github.com/python/cpython/commit/b2f11ca7667e4d57c71c1c88b255115f16042d9a
12CVE: CVE-2024-7592
13
14Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
15Signed-off-by: Hugo SIMELIERE <hsimeliere.opensource@witekio.com>
16---
17 Lib/http/cookies.py | 34 ++++-------------
18 Lib/test/test_http_cookies.py | 38 +++++++++++++++++++
19 ...-08-16-19-13-21.gh-issue-123067.Nx9O4R.rst | 1 +
20 3 files changed, 47 insertions(+), 26 deletions(-)
21 create mode 100644 Misc/NEWS.d/next/Library/2024-08-16-19-13-21.gh-issue-123067.Nx9O4R.rst
22
23diff --git a/Lib/http/cookies.py b/Lib/http/cookies.py
24index 35ac2dc6ae2..2c1f021d0ab 100644
25--- a/Lib/http/cookies.py
26+++ b/Lib/http/cookies.py
27@@ -184,8 +184,13 @@ def _quote(str):
28 return '"' + str.translate(_Translator) + '"'
29
30
31-_OctalPatt = re.compile(r"\\[0-3][0-7][0-7]")
32-_QuotePatt = re.compile(r"[\\].")
33+_unquote_sub = re.compile(r'\\(?:([0-3][0-7][0-7])|(.))').sub
34+
35+def _unquote_replace(m):
36+ if m[1]:
37+ return chr(int(m[1], 8))
38+ else:
39+ return m[2]
40
41 def _unquote(str):
42 # If there aren't any doublequotes,
43@@ -205,30 +210,7 @@ def _unquote(str):
44 # \012 --> \n
45 # \" --> "
46 #
47- i = 0
48- n = len(str)
49- res = []
50- while 0 <= i < n:
51- o_match = _OctalPatt.search(str, i)
52- q_match = _QuotePatt.search(str, i)
53- if not o_match and not q_match: # Neither matched
54- res.append(str[i:])
55- break
56- # else:
57- j = k = -1
58- if o_match:
59- j = o_match.start(0)
60- if q_match:
61- k = q_match.start(0)
62- if q_match and (not o_match or k < j): # QuotePatt matched
63- res.append(str[i:k])
64- res.append(str[k+1])
65- i = k + 2
66- else: # OctalPatt matched
67- res.append(str[i:j])
68- res.append(chr(int(str[j+1:j+4], 8)))
69- i = j + 4
70- return _nulljoin(res)
71+ return _unquote_sub(_unquote_replace, str)
72
73 # The _getdate() routine is used to set the expiration time in the cookie's HTTP
74 # header. By default, _getdate() returns the current time in the appropriate
75diff --git a/Lib/test/test_http_cookies.py b/Lib/test/test_http_cookies.py
76index 6072c7e15e9..644e75cd5b7 100644
77--- a/Lib/test/test_http_cookies.py
78+++ b/Lib/test/test_http_cookies.py
79@@ -5,6 +5,7 @@
80 import unittest
81 from http import cookies
82 import pickle
83+from test import support
84
85
86 class CookieTests(unittest.TestCase):
87@@ -58,6 +59,43 @@ def test_basic(self):
88 for k, v in sorted(case['dict'].items()):
89 self.assertEqual(C[k].value, v)
90
91+ def test_unquote(self):
92+ cases = [
93+ (r'a="b=\""', 'b="'),
94+ (r'a="b=\\"', 'b=\\'),
95+ (r'a="b=\="', 'b=='),
96+ (r'a="b=\n"', 'b=n'),
97+ (r'a="b=\042"', 'b="'),
98+ (r'a="b=\134"', 'b=\\'),
99+ (r'a="b=\377"', 'b=\xff'),
100+ (r'a="b=\400"', 'b=400'),
101+ (r'a="b=\42"', 'b=42'),
102+ (r'a="b=\\042"', 'b=\\042'),
103+ (r'a="b=\\134"', 'b=\\134'),
104+ (r'a="b=\\\""', 'b=\\"'),
105+ (r'a="b=\\\042"', 'b=\\"'),
106+ (r'a="b=\134\""', 'b=\\"'),
107+ (r'a="b=\134\042"', 'b=\\"'),
108+ ]
109+ for encoded, decoded in cases:
110+ with self.subTest(encoded):
111+ C = cookies.SimpleCookie()
112+ C.load(encoded)
113+ self.assertEqual(C['a'].value, decoded)
114+
115+ @support.requires_resource('cpu')
116+ def test_unquote_large(self):
117+ n = 10**6
118+ for encoded in r'\\', r'\134':
119+ with self.subTest(encoded):
120+ data = 'a="b=' + encoded*n + ';"'
121+ C = cookies.SimpleCookie()
122+ C.load(data)
123+ value = C['a'].value
124+ self.assertEqual(value[:3], 'b=\\')
125+ self.assertEqual(value[-2:], '\\;')
126+ self.assertEqual(len(value), n + 3)
127+
128 def test_load(self):
129 C = cookies.SimpleCookie()
130 C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
131diff --git a/Misc/NEWS.d/next/Library/2024-08-16-19-13-21.gh-issue-123067.Nx9O4R.rst b/Misc/NEWS.d/next/Library/2024-08-16-19-13-21.gh-issue-123067.Nx9O4R.rst
132new file mode 100644
133index 00000000000..6a234561fe3
134--- /dev/null
135+++ b/Misc/NEWS.d/next/Library/2024-08-16-19-13-21.gh-issue-123067.Nx9O4R.rst
136@@ -0,0 +1 @@
137+Fix quadratic complexity in parsing ``"``-quoted cookie values with backslashes by :mod:`http.cookies`.
138--
1392.46.0
140