Skip to content

Do not process HTTP/2 request trailer fields as request headers - #1267

Open
arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:h2-trailer-cookie
Open

arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:h2-trailer-cookie

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

When an HTTP/2 request has trailer fields, Stream.receivedEndOfHeaders() runs again at the end of the trailer section and adds the merged cookie header a second time, so the application sees two cookie headers. An allowed cookie trailer field (allowedTrailerHeaders="cookie") is appended to the merged request cookie instead of being exposed as a trailer field, which RFC 9110, section 6.5.1 does not allow. Allowed host, priority and expect trailer fields also go through the request header handling. All of this happens on the connection thread after the request has been passed to a container thread.

Allowed trailer fields are now added directly to the trailer fields, and the end of headers processing is skipped for the trailer section.

Testing:

  • New TestStream.testCookieHeaderWithTrailers and testCookieTrailerAllowed. On main the cookie headers are [a=1; b=2, a=1; b=2], and [a=1; b=2, a=1; b=2; c=3] with no cookie trailer field. With the fix they are [a=1; b=2], and the cookie trailer field is c=3.
  • Local Tomcat built from main, h2c, POST with cookies and trailers: the same results as the tests, before and after the fix.
  • All org.apache.coyote.http2 tests pass.

The merged cookie request header was added again when the end of the
trailer fields was received, so the application saw the cookie header
twice. An allowed cookie trailer field was appended to the merged
cookie value and so merged into the request header section rather than
being exposed as a trailer field. Other allowed trailer fields with
dedicated handling (host, priority, expect) also changed request state.
All of this happened on the connection thread after the request had
been passed to a container thread.

Add allowed trailer fields directly to the trailer fields and skip the
end of request headers processing for the trailer section.
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