Skip to content

SocketsHttpHandler should replace received new lines in headers with spaces #116688

Closed

Description

@MihaZupan

From https://www.rfc-editor.org/rfc/rfc9110.html#section-5.5-5

Field values containing CR, LF, or NUL characters are invalid and dangerous, due to the varying ways that implementations might parse and interpret those characters; a recipient of CR, LF, or NUL within a field value MUST either reject the message or replace each of those characters with SP before further processing or forwarding of that message. Field values containing other CTL characters are also invalid; however, recipients MAY retain such characters for the sake of robustness when they appear within a safe context (e.g., an application-specific quoted string that will not be processed by any downstream HTTP parser).

With HTTP/1.1 it's not possible for a user of HttpClient to observe new lines in the response headers collection since the new line itself is a protocol-level separator.
When parsing HTTP/1.1 line folds, we do replace the new lines with spaces.

// Found an obs-fold (CRLFHT/CRLFSP).
// Replace the CRLF with SPSP and keep looking for the final newline.
valueIterator[crOrLfIdx] = (byte)' ';
valueIterator[lfIdx] = (byte)' ';

But when using HTTP/2 or HTTP/3, we don't check for such characters.

We could choose to also relace the NUL char on HTTP/1.1 as suggested by RFC. Related: #116634

Activity

  1. added this to the 10.0.0 milestone on Jun 16, 2025
  2. dotnet-policy-service commented on Jun 16, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/ncl
    See info in area-owners.md if you want to be subscribed.

  3. self-assigned this
    on Jun 26, 2025
  4. added a commit that references this issue on Jul 9, 2025
    68023ed
  5. locked and limited conversation to collaborators on Aug 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions