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

Skip to content

Commit d161335

Browse files
committed
[3.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 1a1e827 commit d161335

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

django/http/multipartparser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ def parse(self):
248248
remaining = len(stripped_chunk) % 4
249249
while remaining != 0:
250250
over_chunk = field_stream.read(4 - remaining)
251+
if not over_chunk:
252+
break
251253
stripped_chunk += b"".join(over_chunk.split())
252254
remaining = len(stripped_chunk) % 4
253255

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.

docs/releases/3.2.12.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
@@ -143,6 +143,26 @@ def test_big_base64_upload(self):
143143
def test_big_base64_newlines_upload(self):
144144
self._test_base64_upload("Big data" * 68000, encode=base64.encodebytes)
145145

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

0 commit comments

Comments
 (0)