Skip to content

Commit 64c920f

Browse files
authored
Merge pull request #474 from Pylons/bugfix/drop-multiple-chunked-transfer-encodings
If Transfer-Encoding includes "chunked" multiple times, drop request
2 parents 4c8d68e + 7fb8cdb commit 64c920f

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Unreleased
44
Bugfix
55
~~~~~~
66

7+
- Waitress will now drop a request if the Transer-Encoding is set twice in the
8+
request, previously it would decode the chunks and pass it along to the WSGI
9+
application with an appropriate content length. See
10+
https://github.com/Pylons/waitress/issues/465 and
11+
https://github.com/Pylons/waitress/pull/474
12+
713
- When encountering a request that has both Content-Length set and
814
Transfer-Encoding of chunked we now close the connection after it is
915
completed to comply with the requirements of RFC9112. See

src/waitress/parser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,14 @@ def parse_header(self, header_plus):
304304
)
305305

306306
if encodings and encodings[-1] == "chunked":
307+
if (
308+
len([encoding for encoding in encodings if encoding == "chunked"])
309+
!= 1
310+
):
311+
raise TransferEncodingNotImplemented(
312+
"Transfer-Encoding is invalid. Multiple chunked encodings requested."
313+
)
314+
307315
self.chunked = True
308316
buf = OverflowableBuffer(self.adj.inbuf_overflow)
309317
self.body_rcv = ChunkedReceiver(buf)

tests/test_parser.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,19 @@ def test_parse_header_transfer_encoding_invalid_multiple(self):
263263
else: # pragma: nocover
264264
self.assertTrue(False)
265265

266+
def test_parse_header_transfer_encoding_invalid_multiple_chunked(self):
267+
data = b"GET /foobar HTTP/1.1\r\ntransfer-encoding: chunked\r\ntransfer-encoding: chunked\r\n"
268+
269+
try:
270+
self.parser.parse_header(data)
271+
except TransferEncodingNotImplemented as e:
272+
self.assertIn(
273+
"Transfer-Encoding is invalid. Multiple chunked encodings requested.",
274+
e.args[0],
275+
)
276+
else: # pragma: nocover
277+
self.assertTrue(False)
278+
266279
def test_parse_header_transfer_encoding_invalid_whitespace(self):
267280
data = b"GET /foobar HTTP/1.1\r\nTransfer-Encoding:\x85chunked\r\n"
268281

0 commit comments

Comments
 (0)