Commit c7114c0
committed
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.1 parent a87fcdb commit c7114c0
3 files changed
Lines changed: 68 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
465 | 465 | | |
466 | 466 | | |
467 | 467 | | |
468 | | - | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
469 | 471 | | |
470 | 472 | | |
471 | 473 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
474 | 474 | | |
475 | 475 | | |
476 | 476 | | |
477 | | - | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
478 | 523 | | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
479 | 538 | | |
480 | 539 | | |
481 | 540 | | |
| |||
743 | 802 | | |
744 | 803 | | |
745 | 804 | | |
746 | | - | |
747 | | - | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
748 | 808 | | |
749 | 809 | | |
750 | 810 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
111 | 113 | | |
112 | 114 | | |
113 | 115 | | |
| |||
0 commit comments