Fix whitespace-only header line silently truncating headers (fixes #222)#223
Open
scadastrangelove wants to merge 1 commit into
Open
Conversation
…monstar#222) `ParserConfig::allow_space_before_first_header_name(true)` + a line consisting only of whitespace right after the request/status-line silently dropped the entire header block: the parser returned Ok(Status::Complete) with headers == [], leaving every real header unconsumed in the buffer for the caller to misinterpret as body/ next-request bytes. After stripping the leading whitespace run, peek at the next byte before continuing: whitespace-only (next byte is CR/LF) now rejects with the same Error::HeaderName the non-leniency path already uses; no more buffered data returns Status::Partial (preserves streaming correctness). The documented, tested, non-degenerate case (space then a real header) is unaffected. Adds two regression tests (whitespace-only rejection on both request and response sides; the Partial streaming case). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Fixes #222.
ParserConfig::allow_space_before_first_header_name(true)+ a line consisting only of whitespace rightafter the request/status-line silently dropped the entire header block: the parser returned
Ok(Status::Complete)withheaders == [], leaving every real header (Host,Content-Length, ...)unconsumed in the buffer.
The fix
After stripping the leading whitespace run, peek at the next byte before deciding to continue:
\r/\n) now rejects withError::HeaderName— the same errorthe non-leniency path already returns for a malformed first byte, rather than being silently absorbed
as the terminating blank line.
peek()returnsNone), returnsStatus::Partialso the streaming/incremental case is unaffected — a caller that hasn't yet read the byte deciding whitespace-only vs. a
real header isn't penalized.
Tests added
test_allow_space_before_first_header_name_rejects_whitespace_only_line— both request and responsevariants of the whitespace-only-line case now return
Err(HeaderName)instead of silently truncating.test_allow_space_before_first_header_name_partial_after_whitespace— a buffer ending right after thewhitespace run still returns
Status::Partial, confirming the fix doesn't regress incremental parsing.Validation
cargo test --release).test_allow_response_response_with_space_before_first_header(the documented non-degeneratecase) unaffected.
Err(HeaderName)instead ofOk(Complete)/headers==[].Found & fixed with the rust-in-peace security pipeline.