fix(WebRequest): CWE-190/DoS fix and boundary-parsing refactor#447
Open
mathieucarbou wants to merge 1 commit into
Open
fix(WebRequest): CWE-190/DoS fix and boundary-parsing refactor#447mathieucarbou wants to merge 1 commit into
mathieucarbou wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens and refactors multipart boundary= parsing in AsyncWebServerRequest::_parseReqHeader() to reduce allocation overhead during header scanning and to enforce RFC 2046’s 70-character boundary limit as a mitigation for CWE-190/DoS scenarios.
Changes:
- Refactors the
boundary=parameter scan to use raw C-string access and earlier exit conditions. - Reworks boundary value extraction to a single-pass unescape/write path (token or quoted-string) and enforces the 70-char limit early.
- Introduces
std::string_view-based slicing to avoid intermediateString::substring()allocations during parsing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
|
@willmmiles : fyi we cannot use string_view if we want to keep supporting arduino 2 and libretiny. |
521087c to
9ed7c0d
Compare
Tighten multipart boundary parsing in _parseReqHeader(): - Replace String::charAt() inner loop with a raw C-string pointer and pre-computed length for faster, allocation-free scanning. - Add an early-exit upper bound on the scan loop so that positions where 'boundary=' cannot possibly fit are skipped entirely. - Replace the three-pass quoted-string extraction (find close-quote, substring, then unescape) with a single-pass approach that writes directly into _boundary using a raw pointer+length pair — no intermediate heap allocations and no C++17 dependency. - Enforce the RFC 2046 §5.1 70-character limit on boundary length in both token and quoted-string paths; abort with PARSE_REQ_FAIL on violation to prevent CWE-190 integer-overflow / DoS. - Replace strncmp length guard with a position-based early break that is clearer and avoids the redundant cast. - Fix ESP8266 build: String(const char*, size_t) is unavailable; use a 71-byte stack buffer + String(const char*) instead (#ifdef ESP8266). - Fix LibreTiny/C++14 build: remove std::string_view (C++17 only); replaced with plain const char* + size_t throughout. Ref: #445
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tighten multipart boundary parsing in _parseReqHeader():
Ref: #445