Skip to content

SocketsHttpHandler does not enforce request Content-Length correctness #62258

@MihaZupan

Description

@MihaZupan

The Content-Length header we send may not match the number of bytes actually sent.

  • If the custom content is smaller than Content-Length, this will result in the request waiting on either the client or server to time out. The cause of such a hang can be non-obvious (Timeout when request body is consumed before proxying yarp#1412).
  • If the content is larger, it may corrupt the connection for future requests.

SocketsHttpHandler does not currently enforce that the number of bytes sent matches the header. The only exception to that is that HTTP/3 will not allow you to send too much content.

Since this is a protocol violation and non-obvious to diagnose, I suggest that we always throw in case the Content-Length does not match the number of bytes sent. We already track the number of bytes sent (for telemetry purposes), it's just a matter of reacting to a mismatch.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions