61 lines
2.3 KiB
Diff
61 lines
2.3 KiB
Diff
From 24d7b67eac89f94e11003424bcf0d8f7b72222a8 Mon Sep 17 00:00:00 2001
|
|
From: Illia Volochii <illia.volochii@gmail.com>
|
|
Date: Fri, 5 Dec 2025 16:41:33 +0200
|
|
Subject: [PATCH] Merge commit from fork
|
|
|
|
* Add a hard-coded limit for the decompression chain
|
|
|
|
* Reuse new list
|
|
---
|
|
changelog/GHSA-gm62-xv2j-4w53.security.rst | 4 ++++
|
|
src/urllib3/response.py | 12 +++++++++++-
|
|
test/test_response.py | 10 ++++++++++
|
|
3 files changed, 25 insertions(+), 1 deletion(-)
|
|
create mode 100644 changelog/GHSA-gm62-xv2j-4w53.security.rst
|
|
|
|
Index: urllib3-2.5.0/src/urllib3/response.py
|
|
===================================================================
|
|
--- urllib3-2.5.0.orig/src/urllib3/response.py
|
|
+++ urllib3-2.5.0/src/urllib3/response.py
|
|
@@ -342,8 +342,18 @@ class MultiDecoder(ContentDecoder):
|
|
they were applied.
|
|
"""
|
|
|
|
+ # Maximum allowed number of chained HTTP encodings in the
|
|
+ # Content-Encoding header.
|
|
+ max_decode_links = 5
|
|
+
|
|
def __init__(self, modes: str) -> None:
|
|
- self._decoders = [_get_decoder(m.strip()) for m in modes.split(",")]
|
|
+ encodings = [m.strip() for m in modes.split(",")]
|
|
+ if len(encodings) > self.max_decode_links:
|
|
+ raise DecodeError(
|
|
+ "Too many content encodings in the chain: "
|
|
+ f"{len(encodings)} > {self.max_decode_links}"
|
|
+ )
|
|
+ self._decoders = [_get_decoder(e) for e in encodings]
|
|
|
|
def flush(self) -> bytes:
|
|
return self._decoders[0].flush()
|
|
Index: urllib3-2.5.0/test/test_response.py
|
|
===================================================================
|
|
--- urllib3-2.5.0.orig/test/test_response.py
|
|
+++ urllib3-2.5.0/test/test_response.py
|
|
@@ -843,6 +843,16 @@ class TestResponse:
|
|
assert r.read(9 * 37) == b"foobarbaz" * 37
|
|
assert r.read() == b""
|
|
|
|
+ def test_read_multi_decoding_too_many_links(self) -> None:
|
|
+ fp = BytesIO(b"foo")
|
|
+ with pytest.raises(
|
|
+ DecodeError, match="Too many content encodings in the chain: 6 > 5"
|
|
+ ):
|
|
+ HTTPResponse(
|
|
+ fp,
|
|
+ headers={"content-encoding": "gzip, deflate, br, zstd, gzip, deflate"},
|
|
+ )
|
|
+
|
|
def test_body_blob(self) -> None:
|
|
resp = HTTPResponse(b"foo")
|
|
assert resp.data == b"foo"
|