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 the rewind loop variable
from uint8_t to size_t for consistency.
- WebRequest.cpp (_parseReqHeader): validate the boundary value extracted
from the Content-Type header before any body parsing begins:
* Require the 'boundary=' token to be a proper RFC 2045 parameter
(immediately preceded by ';'), preventing substring false-matches.
* Strip optional surrounding whitespace, quotes and trailing parameters
(RFC 2046 quoted-string form).
* 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.
Fix CWE-190: properly parse RFC 2046 quoted-string boundary values
The previous code stripped all double-quote characters from the boundary
string using a blanket replace(), which would silently corrupt boundary
values that contain escaped quotes (\") and could leave a trailing
semi-colon if the quoted string was followed by another parameter.
Replace with a proper RFC 2045/2046 quoted-string parser:
- Token form (no leading quote): trim and stop at the next ';'.
- Quoted-string form (leading '"'): scan forward for the closing quote,
skipping backslash-escaped quotes (\") along the way; extract the
content between the outer quotes. Reject unterminated quoted strings
(missing closing quote) immediately with PARSE_REQ_FAIL + abort().
This was reviewed and proposed by GitHub Copilot Autofix.
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
0 commit comments