h11 icon indicating copy to clipboard operation
h11 copied to clipboard

Better handle of trailing spaces on chunk header - Fixes issue #133

Open bratao opened this issue 3 years ago • 6 comments

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

bratao avatar Jan 26 '22 21:01 bratao

Please also add a comment noting how this production deviates from the standard and why, and also a test.

njsmith avatar Jan 27 '22 03:01 njsmith

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.

bratao avatar Jan 27 '22 04:01 bratao

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 avatar Jan 27 '22 04:01 njsmith

@njsmith Oh, now I get it. See if this comment fits it.

bratao avatar Jan 27 '22 04:01 bratao

Hi guys, thank for the fix! Any ideas when this will get merged?

mariuspodean avatar Mar 15 '22 14:03 mariuspodean

@njsmith do you need me to do anything else to get this upstream?

bratao avatar May 29 '22 23:05 bratao

I've merged this manually and added a test.

pgjones avatar Aug 24 '22 18:08 pgjones