Skip to content

Commit 09449ee

Browse files
committed
clean up docs
1 parent fe899d0 commit 09449ee

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

CHANGES.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ Unreleased
2121
the requested size in one ``read`` call. :issue:`2558`
2222
- A cookie header that starts with ``=`` is treated as an empty key and discarded,
2323
rather than stripping the leading ``==``.
24-
- Specify a maximum number of multipart parts, default 100, after
25-
which a RequestEntityTooLarge exception is raised on parsing. The
26-
mitigates a DOS attack whereby a larger number file/form parts are
27-
sent resulting in a heavy parsing cost.
24+
- Specify a maximum number of multipart parts, default 1000, after which a
25+
``RequestEntityTooLarge`` exception is raised on parsing. This mitigates a DoS
26+
attack where a larger number of form/file parts would result in disproportionate
27+
resource use.
2828

2929

3030
Version 2.2.2

src/werkzeug/formparser.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,8 @@ class FormDataParser:
179179
:param cls: an optional dict class to use. If this is not specified
180180
or `None` the default :class:`MultiDict` is used.
181181
:param silent: If set to False parsing errors will not be caught.
182-
:param max_form_parts: the maximum number of parts to be accepted for the
183-
multipart data sent. If this is exceeded an
184-
:exc:`~exceptions.RequestEntityTooLarge` exception
185-
is raised.
182+
:param max_form_parts: The maximum number of parts to be parsed. If this is
183+
exceeded, a :exc:`~exceptions.RequestEntityTooLarge` exception is raised.
186184
"""
187185

188186
def __init__(
@@ -194,6 +192,7 @@ def __init__(
194192
max_content_length: t.Optional[int] = None,
195193
cls: t.Optional[t.Type[MultiDict]] = None,
196194
silent: bool = True,
195+
*,
197196
max_form_parts: t.Optional[int] = None,
198197
) -> None:
199198
if stream_factory is None:
@@ -204,13 +203,13 @@ def __init__(
204203
self.errors = errors
205204
self.max_form_memory_size = max_form_memory_size
206205
self.max_content_length = max_content_length
206+
self.max_form_parts = max_form_parts
207207

208208
if cls is None:
209209
cls = MultiDict
210210

211211
self.cls = cls
212212
self.silent = silent
213-
self.max_form_parts = max_form_parts
214213

215214
def get_parse_func(
216215
self, mimetype: str, options: t.Dict[str, str]
@@ -419,7 +418,7 @@ def parse(
419418
)
420419

421420
parser = MultipartDecoder(
422-
boundary, self.max_form_memory_size, self.max_form_parts
421+
boundary, self.max_form_memory_size, max_parts=self.max_form_parts
423422
)
424423

425424
fields = []

src/werkzeug/sansio/multipart.py

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def __init__(
8787
self,
8888
boundary: bytes,
8989
max_form_memory_size: Optional[int] = None,
90+
*,
9091
max_parts: Optional[int] = None,
9192
) -> None:
9293
self.buffer = bytearray()

src/werkzeug/wrappers/request.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,9 @@ class Request(_SansIORequest):
8383
#: .. versionadded:: 0.5
8484
max_form_memory_size: t.Optional[int] = None
8585

86-
#: the maximum number of multipart parts. This is forwarded to teh
87-
#: form data parsing function (:func:`parse_form_data`). When the
88-
#: :attr:`form` or :attr:`files` attribute is accessed and the
89-
#: parsing fails because more parts than the specified value is
90-
#: transmitted a :exc:`~werkzeug.exceptions.RequestEntityTooLarge`
91-
#: exception is raised.
86+
#: The maximum number of multipart parts to parse, passed to
87+
#: :attr:`form_data_parser_class`. Parsing form data with more than this
88+
#: many parts will raise :exc:`~.RequestEntityTooLarge`.
9289
#:
9390
#: .. versionadded:: 2.2.3
9491
max_form_parts = 1000

0 commit comments

Comments
 (0)