You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix CWE-190: integer overflow in multipart boundary parser (DoS)
_boundaryPosition was declared as uint8_t. A remote attacker could send a
Content-Type header with a boundary string of exactly 256 bytes, causing the
increment in _parseMultipartPostByte() to overflow back to 0. The parser
would then loop indefinitely in the BOUNDARY_OR_DATA state, consuming 100%
CPU and triggering the FreeRTOS watchdog on ESP32/ESP8266.
Fixes:
- ESPAsyncWebServer.h: change _boundaryPosition from uint8_t to size_t,
eliminating the overflow entirely.
- WebRequest.cpp (_parseMultipartPostByte): change all rewind loop variables
from uint8_t to size_t (BOUNDARY_OR_DATA, DASH3_OR_RETURN2, EXPECT_FEED2).
- WebRequest.cpp (_parseMultipartPostByte / EXPECT_BOUNDARY): add a comment
explaining the intentional unsigned underflow when _parsedLength < 2.
- WebRequest.cpp (_parseReqHeader): validate the boundary value extracted
from the Content-Type header before any body parsing begins:
* Media type comparison changed from case-sensitive startsWith() to a
case-insensitive check on a pre-lowercased copy of the value, so that
e.g. 'Multipart/form-data' is correctly recognised (RFC 2045 §5.1).
* Require the 'boundary=' token to be a proper RFC 2045 parameter
(immediately preceded by ';'), preventing false matches on tokens
whose name merely ends in 'boundary=' (e.g. 'x-boundary=').
* Parse the boundary value as either a token or a quoted-string per
RFC 2046 §5.1. Quoted-string form correctly handles backslash-escaped
quotes ("), pairs of backslashes (\), and rejects unterminated
quoted strings. The closing-quote detector counts consecutive
backslashes before the quote so that an even count (backslashes
cancelling each other) correctly identifies the real closing quote.
* Reject boundaries that are empty or longer than 70 characters
(RFC 2046 §5.1 hard limit); drop the connection immediately with
PARSE_REQ_FAIL + abort() instead of continuing.
* Trim _contentType defensively after extraction.
- AsyncWebHeader.cpp (parse): fix OWS handling per RFC 7230 §3.2.3.
The previous code only skipped a single space after the colon; the
correct rule is OWS = *( SP / HTAB ). This affected every parsed
header: Content-Type, Upgrade, Expect, Transfer-Encoding, Host, etc.
The fix is applied at the source so all header branches benefit.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
0 commit comments