Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c477b76

Browse files
committed
[2.2.x] Fixed CVE-2022-23833 -- Fixed DoS possiblity in file uploads.
Thanks Alan Ryan for the report and initial patch. Backport of fc18f36 from main.
1 parent c27a7eb commit c477b76

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

django/http/multipartparser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ def parse(self):
240240
remaining = len(stripped_chunk) % 4
241241
while remaining != 0:
242242
over_chunk = field_stream.read(4 - remaining)
243+
if not over_chunk:
244+
break
243245
stripped_chunk += b"".join(over_chunk.split())
244246
remaining = len(stripped_chunk) % 4
245247

docs/releases/2.2.27.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ posing an XSS attack vector.
1515
In order to avoid this vulnerability, ``{% debug %}`` no longer outputs an
1616
information when the ``DEBUG`` setting is ``False``, and it ensures all context
1717
variables are correctly escaped when the ``DEBUG`` setting is ``True``.
18+
19+
CVE-2022-23833: Denial-of-service possibility in file uploads
20+
=============================================================
21+
22+
Passing certain inputs to multipart forms could result in an infinite loop when
23+
parsing files.

tests/file_uploads/tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,26 @@ def test_big_base64_upload(self):
142142
def test_big_base64_newlines_upload(self):
143143
self._test_base64_upload("Big data" * 68000, encode=base64.encodebytes)
144144

145+
def test_base64_invalid_upload(self):
146+
payload = client.FakePayload('\r\n'.join([
147+
'--' + client.BOUNDARY,
148+
'Content-Disposition: form-data; name="file"; filename="test.txt"',
149+
'Content-Type: application/octet-stream',
150+
'Content-Transfer-Encoding: base64',
151+
''
152+
]))
153+
payload.write(b'\r\n!\r\n')
154+
payload.write('--' + client.BOUNDARY + '--\r\n')
155+
r = {
156+
'CONTENT_LENGTH': len(payload),
157+
'CONTENT_TYPE': client.MULTIPART_CONTENT,
158+
'PATH_INFO': '/echo_content/',
159+
'REQUEST_METHOD': 'POST',
160+
'wsgi.input': payload,
161+
}
162+
response = self.client.request(**r)
163+
self.assertEqual(response.json()['file'], '')
164+
145165
def test_unicode_file_name(self):
146166
with sys_tempfile.TemporaryDirectory() as temp_dir:
147167
# This file contains Chinese symbols and an accented char in the name.

0 commit comments

Comments
 (0)