File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -514,13 +514,31 @@ bool AsyncWebServerRequest::_parseReqHeader() {
514514 // Extract the boundary value; strip any following parameters, optional
515515 // surrounding whitespace and quotes (RFC 2046 allows quoted-string).
516516 _boundary = value.substring (bpos + (int )T_BOUNDARY_LEN );
517- int semi = _boundary.indexOf (' ;' );
518- if (semi >= 0 ) {
519- _boundary = _boundary.substring (0 , semi);
520- }
521-
522517 _boundary.trim ();
523- _boundary.replace (String (' "' ), String ());
518+
519+ if (_boundary.startsWith (" \" " )) {
520+ int endQuote = 1 ;
521+ while (true ) {
522+ endQuote = _boundary.indexOf (' "' , endQuote);
523+ if (endQuote < 0 || _boundary.charAt (endQuote - 1 ) != ' \\ ' ) {
524+ break ;
525+ }
526+ endQuote++; // skip escaped quote
527+ }
528+ if (endQuote < 0 ) {
529+ async_ws_log_d (" Invalid multipart boundary (unterminated quote), aborting" );
530+ _parseState = PARSE_REQ_FAIL ;
531+ abort ();
532+ return true ;
533+ }
534+ _boundary = _boundary.substring (1 , endQuote);
535+ } else {
536+ int semi = _boundary.indexOf (' ;' );
537+ if (semi >= 0 ) {
538+ _boundary = _boundary.substring (0 , semi);
539+ }
540+ _boundary.trim ();
541+ }
524542
525543 // CWE-190 / DoS fix: RFC 2046 §5.1 limits boundary strings to 70
526544 // characters. _boundaryPosition was formerly uint8_t, so a boundary
You can’t perform that action at this time.
0 commit comments