mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
[4.2.x] Fixed CVE-2023-24580 -- Prevented DoS with too many uploaded files.
Thanks to Jakob Ackermann for the report.
This commit is contained in:
committed by
Carlton Gibson
parent
de42d51361
commit
7ac5ff37b8
@@ -1,6 +1,10 @@
|
||||
from io import BytesIO
|
||||
|
||||
from django.core.exceptions import RequestDataTooBig, TooManyFieldsSent
|
||||
from django.core.exceptions import (
|
||||
RequestDataTooBig,
|
||||
TooManyFieldsSent,
|
||||
TooManyFilesSent,
|
||||
)
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.test import SimpleTestCase
|
||||
from django.test.client import FakePayload
|
||||
@@ -8,6 +12,9 @@ from django.test.client import FakePayload
|
||||
TOO_MANY_FIELDS_MSG = (
|
||||
"The number of GET/POST parameters exceeded settings.DATA_UPLOAD_MAX_NUMBER_FIELDS."
|
||||
)
|
||||
TOO_MANY_FILES_MSG = (
|
||||
"The number of files exceeded settings.DATA_UPLOAD_MAX_NUMBER_FILES."
|
||||
)
|
||||
TOO_MUCH_DATA_MSG = "Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE."
|
||||
|
||||
|
||||
@@ -191,6 +198,52 @@ class DataUploadMaxNumberOfFieldsMultipartPost(SimpleTestCase):
|
||||
self.request._load_post_and_files()
|
||||
|
||||
|
||||
class DataUploadMaxNumberOfFilesMultipartPost(SimpleTestCase):
|
||||
def setUp(self):
|
||||
payload = FakePayload(
|
||||
"\r\n".join(
|
||||
[
|
||||
"--boundary",
|
||||
(
|
||||
'Content-Disposition: form-data; name="name1"; '
|
||||
'filename="name1.txt"'
|
||||
),
|
||||
"",
|
||||
"value1",
|
||||
"--boundary",
|
||||
(
|
||||
'Content-Disposition: form-data; name="name2"; '
|
||||
'filename="name2.txt"'
|
||||
),
|
||||
"",
|
||||
"value2",
|
||||
"--boundary--",
|
||||
]
|
||||
)
|
||||
)
|
||||
self.request = WSGIRequest(
|
||||
{
|
||||
"REQUEST_METHOD": "POST",
|
||||
"CONTENT_TYPE": "multipart/form-data; boundary=boundary",
|
||||
"CONTENT_LENGTH": len(payload),
|
||||
"wsgi.input": payload,
|
||||
}
|
||||
)
|
||||
|
||||
def test_number_exceeded(self):
|
||||
with self.settings(DATA_UPLOAD_MAX_NUMBER_FILES=1):
|
||||
with self.assertRaisesMessage(TooManyFilesSent, TOO_MANY_FILES_MSG):
|
||||
self.request._load_post_and_files()
|
||||
|
||||
def test_number_not_exceeded(self):
|
||||
with self.settings(DATA_UPLOAD_MAX_NUMBER_FILES=2):
|
||||
self.request._load_post_and_files()
|
||||
|
||||
def test_no_limit(self):
|
||||
with self.settings(DATA_UPLOAD_MAX_NUMBER_FILES=None):
|
||||
self.request._load_post_and_files()
|
||||
|
||||
|
||||
class DataUploadMaxNumberOfFieldsFormPost(SimpleTestCase):
|
||||
def setUp(self):
|
||||
payload = FakePayload("\r\n".join(["a=1&a=2&a=3", ""]))
|
||||
|
||||
Reference in New Issue
Block a user