Skip to content

SocketsHttpHandler does not check for Transfer-Encoding: chunked on response properly  #63053

Closed

Description

@geoffkizer

For every HTTP/1.1 response, we need to check for Transfer-Encoding: chunked. We do this by calling HttpHeaders.ContainsParsedValue.

This check will succeed if "chunked" appears anywhere in the Transfer-Encoding list. However, Transfer-Encodings are ordered and so the check should only succeed if "chunked" is the final Transfer-Encoding value.

Note that sending "chunked" as a non-final Transfer-Encoding value is invalid server behavior, so we are only doing this incorrectly when the server is misbehaving. Still, we should adhere to the RFC here.

Relevant RFC: https://www.rfc-editor.org/rfc/rfc7230.html#section-3.3.1

Activity

  1. ghost added
    untriaged
    on Dec 21, 2021
  2. geoffkizer commented on Dec 21, 2021

    @geoffkizer
    ContributorAuthor

    Note this applies to both the public HttpResponseHeaders.TransferEncodingChunked property as well as our internal handling of Transfer-Encoding: chunked in HttpConnection (which uses the TransferEncodingChunked property today). We should ensure both are fixed.

  3. MihaZupan commented on Dec 21, 2021

    @MihaZupan
    Member

    Related: We should likely invert the order of checking Content-Length and Transfer-Encoding when both are present: #62906 (comment)

  4. geoffkizer commented on Dec 21, 2021

    @geoffkizer
    ContributorAuthor

    Note also, this applies to setting the HttpResponseHeaders.TransferEncodingChunked property as well. It should only remove "chunked" if it is the final Transfer-Encoding value.

  5. added this to the Future milestone on Jan 18, 2022
  6. added and removed
    untriaged
    on Jan 18, 2022
  7. karelz commented on Jan 18, 2022

    @karelz
    Member

    Triage: Corner case, but still a bug.

  8. self-assigned this
    on Jul 22, 2024
  9. rokonec commented on Jul 29, 2024

    @rokonec
    Member

    Related: We should likely invert the order of checking Content-Length and Transfer-Encoding when both are present: #62906 (comment)

    This has been already fixed

  10. added
    in-pr
    on Jul 29, 2024
  11. rokonec commented on Aug 5, 2024

    @rokonec
    Member

    I was trying to understand risks of proposed solution in #105647
    In order to do that I have studied how common HTTP Client handle Transport-Encoding, created some simple local HTTP server and tested it.
    I have found that Transport-Encoding other than chunked is not implemented in any well used HTTP client. I have tested Chrome, Safari and curl and looked at source code of Kestrel and HttpClient.

    I came to conclusion that current behavior of HttpClient is consistent with other major endpoint HTTP client implementations, i.e. if chunked appears in any order in Transfer-Encoding response is considered chunked.

    For this reason I see any functional changes to current behavior as risky, same as chromium authors did in https://issues.chromium.org/issues/40620688

    I therefore recommend to close this issue and linked PR as by-design.

    @MihaZupan @karelz @ManickaP

  12. ManickaP commented on Aug 8, 2024

    @ManickaP
    Member

    I did some RFC reading and this part is interesting [6.3. Message Body Length](https://httpwg.org/specs/rfc9112.html#message.body.length) point 4.:

    If a Transfer-Encoding header field is present in a response and the chunked transfer coding is not the final encoding, the message body length is determined by reading the connection until it is closed by the server.

    BUT, this was internally found and not reported by anyone, so I'm fine with keeping our behavior as-is.
    I'm also fine with closing this. In case we have anyone reporting issue with the current behavior, we can always revisit this decision.

  13. MihaZupan commented on Aug 12, 2024

    @MihaZupan
    Member

    I therefore recommend to close this issue and linked PR as by-design.

    👍 as we've discussed, I agree changing this would be risky. Thanks for checking how other implementations behave here.

  14. locked and limited conversation to collaborators on Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Net.Httpbugin-pr

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions