Harden WebSocket request parsing for header casing, body bounds, cookie conversion, and MinGW portability - #27
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix case-sensitive comparison for HTTP header fields
Harden WebSocket request parsing for header casing, body bounds, and cookie conversion
Jun 9, 2026
|
@copilot CI is red for mingw, fix it please. |
Author
Copilot
AI
changed the title
Harden WebSocket request parsing for header casing, body bounds, and cookie conversion
Harden WebSocket request parsing for header casing, body bounds, cookie conversion, and MinGW portability
Jun 9, 2026
The outer guard `strstr(cont_len, "\r\n\r\n")` already proves the sequence is present in the buffer. Since cont_len is a pointer into m_pBuf, strstr(m_pBuf, "\r\n\r\n") is guaranteed to succeed, so the subsequent NULL check is unreachable.
strstr returns NULL or a pointer within its haystack; it can never return a value less than the haystack base. The cont < m_pBuf branch is unreachable on any conforming implementation.
std::isspace already returns true for '\r' and '\n', making the two explicit comparisons in the cookie endptr validation redundant.
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.
Summary
This PR hardens
CWebSocketHTTP parsing in three places: case-insensitiveContent-Lengthhandling, safe POST body boundary checks without signed/unsigned pitfalls, and strictstrtoullcookie parsing validation to reject malformed session IDs.Header name matching
Content-Lengthso mixed-case headers are handled correctly.FindHeaderCaseInsensitive) usingstrncasecmp, instead ofstrcasestr, to keep MinGW builds green.POST body length/bounds validation
Session cookie parsing hardening
strtoullconversion usingerrno+endptr.sessid.Test plan
strcasestrunavailable on that toolchain) and updated the implementation to a portable case-insensitive header search.strcasestr.Original prompt