Better handle of trailing spaces on chunk header - Fixes issue #133
Hello,
I found some servers that return multiple trailing spaces on the chunk header. I changed the regex to match on those cases. This fixes issue #133
Please also add a comment noting how this production deviates from the standard and why, and also a test.
Following https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.1 , thje grammar is the following:
The chunked transfer coding wraps the payload body in order to
transfer it as a series of chunks, each with its own size indicator,
followed by an OPTIONAL trailer containing header fields. Chunked
enables content streams of unknown size to be transferred as a
sequence of length-delimited buffers, which enables the sender to
retain connection persistence and the recipient to know when it has
received the entire message.
chunked-body = *chunk
last-chunk
trailer-part
CRLF
chunk = chunk-size [ chunk-ext ] CRLF
chunk-data CRLF
chunk-size = 1*HEXDIG
last-chunk = 1*("0") [ chunk-ext ] CRLF
chunk-data = 1*OCTET ; a sequence of chunk-size octets
The chunk-size field is a string of hex digits indicating the size of
the chunk-data in octets. The chunked transfer coding is complete
when a chunk with a chunk-size of zero is received, possibly followed
by a trailer, and finally terminated by an empty line.
A recipient MUST be able to parse and decode the chunked transfer
coding.
I cannot see why a server would add an empty space on this part. Maybe as a bad coded placeholder for [ chunk-ext ].
But I seen this on the wild ( and #133), and I cannot image a security problem or any kind of request smuggling by skipping the white spaces.
Sorry, I meant a # comment in the source code :-) So the next person reading the code isn't confused about why the production in the code doesn't match the one in the spec.
@njsmith Oh, now I get it. See if this comment fits it.
Hi guys, thank for the fix! Any ideas when this will get merged?
@njsmith do you need me to do anything else to get this upstream?
I've merged this manually and added a test.