Skip to content

Accept BWS between the chunk size and the first chunk extension - #1261

Open
arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:chunk-size-bws
Open

arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:chunk-size-bws

Conversation

@arturobernalg

@arturobernalg arturobernalg commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

RFC 9112, section 7.1.1 defines

chunk-ext = *( BWS ";" BWS chunk-ext-name [ BWS "=" BWS chunk-ext-val ] )

and RFC 9110, section 5.6.3 states "A recipient MUST parse for such bad whitespace and remove it before interpreting the protocol element".

ChunkExtension already accepts BWS after the first semicolon (and TestChunkExtension models optional whitespace before it), but ChunkedInputFilter handled the bytes between the chunk size and the first semicolon itself and treated whitespace as an invalid hex digit, so 3 ;a=b was rejected.

Whitespace is now accepted after the chunk size only when it is followed by a chunk extension. A chunk size followed by whitespace and CRLF (not allowed by the grammar), whitespace before the chunk size and whitespace within the chunk size are still rejected.

Tested on a local Tomcat (chunked POST read by a servlet), compared with httpd 2.4.69 (mod_dav PUT) and Netty 4.1.130 (HttpRequestDecoder):

chunk header before after httpd Netty
3 ; ext=val rejected accepted accepted accepted
3\t;ext rejected accepted accepted accepted
3 + CRLF rejected rejected accepted accepted
3;ext rejected rejected 400 accepted

The tests for the accepted chunk headers (testChunkSizeBwsBeforeExtension, testChunkSizeBwsTabBeforeExtension) fail without the change; the other new tests check that invalid chunk headers are still rejected.

RFC 9112, section 7.1.1 defines chunk-ext as
*( BWS ";" BWS chunk-ext-name [ BWS "=" BWS chunk-ext-val ] ) and
RFC 9110, section 5.6.3 requires a recipient to parse and remove BWS.
The chunk extension parser already accepted BWS after the first
semicolon, but whitespace between the chunk size and the first
semicolon was treated as an invalid hex digit and the request was
rejected.

Whitespace is now accepted after the chunk size only when it is followed
by a chunk extension. A chunk size followed by whitespace and CRLF, or
whitespace before or within the chunk size, is still rejected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant