summaryrefslogtreecommitdiffstats
path: root/meta-python/recipes-devtools/python/python3-twisted/CVE-2024-41671-0002.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-python/recipes-devtools/python/python3-twisted/CVE-2024-41671-0002.patch')
-rw-r--r--meta-python/recipes-devtools/python/python3-twisted/CVE-2024-41671-0002.patch251
1 files changed, 251 insertions, 0 deletions
diff --git a/meta-python/recipes-devtools/python/python3-twisted/CVE-2024-41671-0002.patch b/meta-python/recipes-devtools/python/python3-twisted/CVE-2024-41671-0002.patch
new file mode 100644
index 0000000000..147c21d73d
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-twisted/CVE-2024-41671-0002.patch
@@ -0,0 +1,251 @@
1From 4a930de12fb67e88fefcb8822104152f42b27abc Mon Sep 17 00:00:00 2001
2From: Adi Roiban <adiroiban@gmail.com>
3Date: Mon Jul 29 14:27:23 2024 +0100
4Subject: [PATCH] Merge commit from fork
5
6Address GHSA-c8m8-j448-xjx7
7
8CVE: CVE-2024-41671
9
10Upstream-Status: Backport [https://github.com/twisted/twisted/commit/4a930de12fb67e88fefcb8822104152f42b27abc]
11
12Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com>
13---
14 src/twisted/web/http.py | 21 +++--
15 src/twisted/web/test/test_http.py | 122 ++++++++++++++++++++++++++----
16 2 files changed, 122 insertions(+), 21 deletions(-)
17
18diff --git a/src/twisted/web/http.py b/src/twisted/web/http.py
19index 1c59838..3b784f5 100644
20--- a/src/twisted/web/http.py
21+++ b/src/twisted/web/http.py
22@@ -2000,16 +2000,21 @@ class _ChunkedTransferDecoder:
23 @returns: C{False}, as there is either insufficient data to continue,
24 or no data remains.
25 """
26- if (
27- self._receivedTrailerHeadersSize + len(self._buffer)
28- > self._maxTrailerHeadersSize
29- ):
30- raise _MalformedChunkedDataError("Trailer headers data is too long.")
31-
32 eolIndex = self._buffer.find(b"\r\n", self._start)
33
34 if eolIndex == -1:
35 # Still no end of network line marker found.
36+ #
37+ # Check if we've run up against the trailer size limit: if the next
38+ # read contains the terminating CRLF then we'll have this many bytes
39+ # of trailers (including the CRLFs).
40+ minTrailerSize = (
41+ self._receivedTrailerHeadersSize
42+ + len(self._buffer)
43+ + (1 if self._buffer.endswith(b"\r") else 2)
44+ )
45+ if minTrailerSize > self._maxTrailerHeadersSize:
46+ raise _MalformedChunkedDataError("Trailer headers data is too long.")
47 # Continue processing more data.
48 return False
49
50@@ -2019,6 +2024,8 @@ class _ChunkedTransferDecoder:
51 del self._buffer[0 : eolIndex + 2]
52 self._start = 0
53 self._receivedTrailerHeadersSize += eolIndex + 2
54+ if self._receivedTrailerHeadersSize > self._maxTrailerHeadersSize:
55+ raise _MalformedChunkedDataError("Trailer headers data is too long.")
56 return True
57
58 # eolIndex in this part of code is equal to 0
59@@ -2342,8 +2349,8 @@ class HTTPChannel(basic.LineReceiver, policies.TimeoutMixin):
60 self.__header = line
61
62 def _finishRequestBody(self, data):
63- self.allContentReceived()
64 self._dataBuffer.append(data)
65+ self.allContentReceived()
66
67 def _maybeChooseTransferDecoder(self, header, data):
68 """
69diff --git a/src/twisted/web/test/test_http.py b/src/twisted/web/test/test_http.py
70index 33d0a49..1130d31 100644
71--- a/src/twisted/web/test/test_http.py
72+++ b/src/twisted/web/test/test_http.py
73@@ -135,7 +135,7 @@ class DummyHTTPHandler(http.Request):
74 data = self.content.read()
75 length = self.getHeader(b"content-length")
76 if length is None:
77- length = networkString(str(length))
78+ length = str(length).encode()
79 request = b"'''\n" + length + b"\n" + data + b"'''\n"
80 self.setResponseCode(200)
81 self.setHeader(b"Request", self.uri)
82@@ -563,17 +563,23 @@ class HTTP0_9Tests(HTTP1_0Tests):
83
84 class PipeliningBodyTests(unittest.TestCase, ResponseTestMixin):
85 """
86- Tests that multiple pipelined requests with bodies are correctly buffered.
87+ Pipelined requests get buffered and executed in the order received,
88+ not processed in parallel.
89 """
90
91 requests = (
92 b"POST / HTTP/1.1\r\n"
93 b"Content-Length: 10\r\n"
94 b"\r\n"
95- b"0123456789POST / HTTP/1.1\r\n"
96- b"Content-Length: 10\r\n"
97- b"\r\n"
98 b"0123456789"
99+ # Chunk encoded request.
100+ b"POST / HTTP/1.1\r\n"
101+ b"Transfer-Encoding: chunked\r\n"
102+ b"\r\n"
103+ b"a\r\n"
104+ b"0123456789\r\n"
105+ b"0\r\n"
106+ b"\r\n"
107 )
108
109 expectedResponses = [
110@@ -590,14 +596,16 @@ class PipeliningBodyTests(unittest.TestCase, ResponseTestMixin):
111 b"Request: /",
112 b"Command: POST",
113 b"Version: HTTP/1.1",
114- b"Content-Length: 21",
115- b"'''\n10\n0123456789'''\n",
116+ b"Content-Length: 23",
117+ b"'''\nNone\n0123456789'''\n",
118 ),
119 ]
120
121- def test_noPipelining(self):
122+ def test_stepwiseTinyTube(self):
123 """
124- Test that pipelined requests get buffered, not processed in parallel.
125+ Imitate a slow connection that delivers one byte at a time.
126+ The request handler (L{DelayedHTTPHandler}) is puppeted to
127+ step through the handling of each request.
128 """
129 b = StringTransport()
130 a = http.HTTPChannel()
131@@ -606,10 +614,9 @@ class PipeliningBodyTests(unittest.TestCase, ResponseTestMixin):
132 # one byte at a time, to stress it.
133 for byte in iterbytes(self.requests):
134 a.dataReceived(byte)
135- value = b.value()
136
137 # So far only one request should have been dispatched.
138- self.assertEqual(value, b"")
139+ self.assertEqual(b.value(), b"")
140 self.assertEqual(1, len(a.requests))
141
142 # Now, process each request one at a time.
143@@ -618,8 +625,91 @@ class PipeliningBodyTests(unittest.TestCase, ResponseTestMixin):
144 request = a.requests[0].original
145 request.delayedProcess()
146
147- value = b.value()
148- self.assertResponseEquals(value, self.expectedResponses)
149+ self.assertResponseEquals(b.value(), self.expectedResponses)
150+
151+ def test_stepwiseDumpTruck(self):
152+ """
153+ Imitate a fast connection where several pipelined
154+ requests arrive in a single read. The request handler
155+ (L{DelayedHTTPHandler}) is puppeted to step through the
156+ handling of each request.
157+ """
158+ b = StringTransport()
159+ a = http.HTTPChannel()
160+ a.requestFactory = DelayedHTTPHandlerProxy
161+ a.makeConnection(b)
162+
163+ a.dataReceived(self.requests)
164+
165+ # So far only one request should have been dispatched.
166+ self.assertEqual(b.value(), b"")
167+ self.assertEqual(1, len(a.requests))
168+
169+ # Now, process each request one at a time.
170+ while a.requests:
171+ self.assertEqual(1, len(a.requests))
172+ request = a.requests[0].original
173+ request.delayedProcess()
174+
175+ self.assertResponseEquals(b.value(), self.expectedResponses)
176+
177+ def test_immediateTinyTube(self):
178+ """
179+ Imitate a slow connection that delivers one byte at a time.
180+ (L{DummyHTTPHandler}) immediately responds, but no more
181+ than one
182+ """
183+ b = StringTransport()
184+ a = http.HTTPChannel()
185+ a.requestFactory = DummyHTTPHandlerProxy # "sync"
186+ a.makeConnection(b)
187+
188+ # one byte at a time, to stress it.
189+ for byte in iterbytes(self.requests):
190+ a.dataReceived(byte)
191+ # There is never more than one request dispatched at a time:
192+ self.assertLessEqual(len(a.requests), 1)
193+
194+ self.assertResponseEquals(b.value(), self.expectedResponses)
195+
196+ def test_immediateDumpTruck(self):
197+ """
198+ Imitate a fast connection where several pipelined
199+ requests arrive in a single read. The request handler
200+ (L{DummyHTTPHandler}) immediately responds.
201+ This doesn't check the at-most-one pending request
202+ invariant but exercises otherwise uncovered code paths.
203+ See GHSA-c8m8-j448-xjx7.
204+ """
205+ b = StringTransport()
206+ a = http.HTTPChannel()
207+ a.requestFactory = DummyHTTPHandlerProxy
208+ a.makeConnection(b)
209+
210+ # All bytes at once to ensure there's stuff to buffer.
211+ a.dataReceived(self.requests)
212+
213+ self.assertResponseEquals(b.value(), self.expectedResponses)
214+
215+ def test_immediateABiggerTruck(self):
216+ """
217+ Imitate a fast connection where a so many pipelined
218+ requests arrive in a single read that backpressure is indicated.
219+ The request handler (L{DummyHTTPHandler}) immediately responds.
220+ This doesn't check the at-most-one pending request
221+ invariant but exercises otherwise uncovered code paths.
222+ See GHSA-c8m8-j448-xjx7.
223+ @see: L{http.HTTPChannel._optimisticEagerReadSize}
224+ """
225+ b = StringTransport()
226+ a = http.HTTPChannel()
227+ a.requestFactory = DummyHTTPHandlerProxy
228+ a.makeConnection(b)
229+
230+ overLimitCount = a._optimisticEagerReadSize // len(self.requests) * 10
231+ a.dataReceived(self.requests * overLimitCount)
232+
233+ self.assertResponseEquals(b.value(), self.expectedResponses * overLimitCount)
234
235 def test_pipeliningReadLimit(self):
236 """
237@@ -1522,7 +1612,11 @@ class ChunkedTransferEncodingTests(unittest.TestCase):
238 lambda b: None, # pragma: nocov
239 )
240 p._maxTrailerHeadersSize = 10
241- p.dataReceived(b"3\r\nabc\r\n0\r\n0123456789")
242+ # 9 bytes are received so far, in 2 packets.
243+ # For now, all is ok.
244+ p.dataReceived(b"3\r\nabc\r\n0\r\n01234567")
245+ p.dataReceived(b"\r")
246+ # Once the 10th byte is received, the processing fails.
247 self.assertRaises(
248 http._MalformedChunkedDataError,
249 p.dataReceived,
250--
2512.40.0