Werkzeug vulnerable to high resource usage when parsing multipart/form-data containing a large part with CR/LF character at the beginning
Description
Werkzeug is a comprehensive WSGI web application library. If an upload of a file that starts with CR or LF and then is followed by megabytes of data without these characters: all of these bytes are appended chunk by chunk into internal bytearray and lookup for boundary is performed on growing buffer. This allows an attacker to cause a denial of service by sending crafted multipart data to an endpoint that will parse it. The amount of CPU time required can block worker processes from handling legitimate requests. This vulnerability has been patched in version 3.0.1.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
werkzeugPyPI | >= 3.0.0, < 3.0.1 | 3.0.1 |
werkzeugPyPI | < 2.3.8 | 2.3.8 |
Affected products
1Patches
33 files changed · +18 −2
CHANGES.rst+8 −0 modified@@ -1,5 +1,13 @@ .. currentmodule:: werkzeug +Version 3.0.1 +------------- + +Released 2023-10-24 + +- Fix slow multipart parsing for large parts potentially enabling DoS + attacks. :cwe:`CWE-407` + Version 3.0.0 -------------
pyproject.toml+1 −1 modified@@ -1,6 +1,6 @@ [project] name = "Werkzeug" -version = "3.0.0" +version = "3.0.1" description = "The comprehensive WSGI web application library." readme = "README.rst" license = {file = "LICENSE.rst"}
src/werkzeug/sansio/multipart.py+9 −1 modified@@ -251,12 +251,20 @@ def _parse_data(self, data: bytes, *, start: bool) -> tuple[bytes, int, bool]: else: data_start = 0 - if self.buffer.find(b"--" + self.boundary) == -1: + boundary = b"--" + self.boundary + + if self.buffer.find(boundary) == -1: # No complete boundary in the buffer, but there may be # a partial boundary at the end. As the boundary # starts with either a nl or cr find the earliest and # return up to that as data. data_end = del_index = self.last_newline(data[data_start:]) + data_start + # If amount of data after last newline is far from + # possible length of partial boundary, we should + # assume that there is no partial boundary in the buffer + # and return all pending data. + if (len(data) - data_end) > len(b"\n" + boundary): + data_end = del_index = len(data) more_data = True else: match = self.boundary_re.search(data)
b1916c0c083eFix: slow multipart parsing for huge files with few CR/LF characters
1 file changed · +9 −1
src/werkzeug/sansio/multipart.py+9 −1 modified@@ -251,12 +251,20 @@ def _parse_data(self, data: bytes, *, start: bool) -> tuple[bytes, int, bool]: else: data_start = 0 - if self.buffer.find(b"--" + self.boundary) == -1: + boundary = b"--" + self.boundary + + if self.buffer.find(boundary) == -1: # No complete boundary in the buffer, but there may be # a partial boundary at the end. As the boundary # starts with either a nl or cr find the earliest and # return up to that as data. data_end = del_index = self.last_newline(data[data_start:]) + data_start + # If amount of data after last newline is far from + # possible length of partial boundary, we should + # assume that there is no partial boundary in the buffer + # and return all pending data. + if (len(data) - data_end) > len(b"\n" + boundary): + data_end = del_index = len(data) more_data = True else: match = self.boundary_re.search(data)
f2300208d5e2Fix: slow multipart parsing for huge files with few CR/LF characters
1 file changed · +9 −1
src/werkzeug/sansio/multipart.py+9 −1 modified@@ -251,12 +251,20 @@ def _parse_data(self, data: bytes, *, start: bool) -> tuple[bytes, int, bool]: else: data_start = 0 - if self.buffer.find(b"--" + self.boundary) == -1: + boundary = b"--" + self.boundary + + if self.buffer.find(boundary) == -1: # No complete boundary in the buffer, but there may be # a partial boundary at the end. As the boundary # starts with either a nl or cr find the earliest and # return up to that as data. data_end = del_index = self.last_newline(data[data_start:]) + data_start + # If amount of data after last newline is far from + # possible length of partial boundary, we should + # assume that there is no partial boundary in the buffer + # and return all pending data. + if (len(data) - data_end) > len(b"\n" + boundary): + data_end = del_index = len(data) more_data = True else: match = self.boundary_re.search(data)
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
9- github.com/advisories/GHSA-hrfv-mqp8-q5rwghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2023-46136ghsaADVISORY
- github.com/pallets/werkzeug/commit/b1916c0c083e0be1c9d887ee2f3d696922bfc5c1ghsaWEB
- github.com/pallets/werkzeug/commit/f2300208d5e2a5076cbbb4c2aad71096fd040ef9ghsaWEB
- github.com/pallets/werkzeug/commit/f3c803b3ade485a45f12b6d6617595350c0f03e2ghsax_refsource_MISCWEB
- github.com/pallets/werkzeug/security/advisories/GHSA-hrfv-mqp8-q5rwghsax_refsource_CONFIRMWEB
- github.com/pypa/advisory-database/tree/main/vulns/werkzeug/PYSEC-2023-221.yamlghsaWEB
- security.netapp.com/advisory/ntap-20231124-0008ghsaWEB
- security.netapp.com/advisory/ntap-20231124-0008/mitre
News mentions
0No linked articles in our index yet.