Skip to content

Limit header name in HtppListenerRequest - #132163

Merged
iremyux merged 5 commits into
dotnet:mainfrom
iremyux:132128-htpprequest-check
Aug 14, 2026
Merged

Limit header name in HtppListenerRequest#132163
iremyux merged 5 commits into
dotnet:mainfrom
iremyux:132128-htpprequest-check

Conversation

@iremyux

@iremyux iremyux commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #132128

@iremyux iremyux added this to the 12.0.0 milestone Aug 11, 2026
@iremyux iremyux self-assigned this Aug 11, 2026
Copilot AI lite review requested due to automatic review settings August 11, 2026 19:42
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens request header parsing in the managed HttpListener implementation to reject malformed header field names that include leading whitespace or whitespace before the : separator, aligning behavior with HTTP requirements while preserving optional whitespace trimming around header values.

Changes:

  • Reject request headers whose field-name contains ASCII space or tab before the colon in the managed HttpListener request parser.
  • Stop trimming the header name (field-name) during parsing; continue trimming only ASCII space/tab around the field-value.
  • Add managed-implementation-only regression coverage for malformed header names with leading whitespace or whitespace before :.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Net.HttpListener/tests/InvalidClientRequestTests.cs Adds managed-only invalid request cases for header names with leading whitespace or whitespace before the colon.
src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpListenerRequest.Managed.cs Updates managed header parsing to validate field-name without trimming and reject space/tab in the name portion; trims only SP/HTAB around values.

@iremyux
iremyux marked this pull request as ready for review August 11, 2026 20:19
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI review requested due to automatic review settings August 12, 2026 09:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpListenerRequest.Managed.cs:212

  • s_validMethodChars is now used to validate both the HTTP method token and the header field-name token. The character set is correct for both, but the name has become misleading and makes it harder to understand why method-validation logic is being reused for header parsing. Consider renaming it to something like s_validTokenChars (and updating both call sites) to match its broader purpose.
            int colon = header.IndexOf(':');
            if (colon <= 0 || header.AsSpan(0, colon).ContainsAnyExcept(s_validMethodChars))
            {

Copilot AI review requested due to automatic review settings August 12, 2026 13:12
@iremyux
iremyux enabled auto-merge (squash) August 12, 2026 13:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 14, 2026 08:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Managed HttpListener accepts whitespace around request header names

3 participants