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

Skip to content

Commit fc18f36

Browse files
committed
Fixed CVE-2022-23833 -- Fixed DoS possiblity in file uploads.
Thanks Alan Ryan for the report and initial patch.
1 parent 394517f commit fc18f36

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-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.

docs/releases/4.0.2.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ In order to avoid this vulnerability, ``{% debug %}`` no longer outputs an
1818
information when the ``DEBUG`` setting is ``False``, and it ensures all context
1919
variables are correctly escaped when the ``DEBUG`` setting is ``True``.
2020

21+
CVE-2022-23833: Denial-of-service possibility in file uploads
22+
=============================================================
23+
24+
Passing certain inputs to multipart forms could result in an infinite loop when
25+
parsing files.
26+
2127
Bugfixes
2228
========
2329

tests/file_uploads/tests.py

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

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

0 commit comments

Comments
 (0)