Skip to content

Guard Kestrel method hash against non-ASCII starts - #70301

Merged
hoyosjs merged 1 commit into
dotnet:mainfrom
hoyosjs:juhoyosa/method-pseudo
Nov 10, 2026
Merged

hoyosjs merged 1 commit into
dotnet:mainfrom
hoyosjs:juhoyosa/method-pseudo

Conversation

@hoyosjs

@hoyosjs hoyosjs commented Nov 4, 2026

Copy link
Copy Markdown
Member

Guard Kestrel's method hash against non-ASCII starts

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Skip the known-method hash lookup for non-ASCII first characters.

Description

GetKnownMethod(string) hashes 3-7-character methods before HTTP/2 and HTTP/3 validate token characters. Indexing the 256-entry hash table with a leading U+0100 or higher throws IndexOutOfRangeException.

Check char.IsAscii(value[0]) before hashing so malformed methods reach the existing custom-method validator. No public API changes.

Regression coverage checks every affected length and the upper UTF-16 boundary, plus real UTF-8 HPACK/QPACK HEADERS at lengths 3 and 7. All seven unit cases and all four protocol cases fail without the fix in Release and pass with it in Debug and Release.

Fixes #70300

Validation

Parser checks: 200 passed in each configuration. Protocol method checks: 19 passed in each configuration. No failures or skips. Changed-file formatting checks and git diff --check passed.

Exact test commands (all passed)

Run from the repository root after . .\activate.ps1.

dotnet test .\src\Servers\Kestrel\Core\test\Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj -c Release --no-restore --filter "FullyQualifiedName~HttpUtilitiesTest|FullyQualifiedName~KnownStringsTests" --logger "console;verbosity=minimal"
dotnet test .\src\Servers\Kestrel\test\InMemory.FunctionalTests\InMemory.FunctionalTests.csproj -c Release --no-restore --filter "FullyQualifiedName~NonAsciiMethodStart_Reset|FullyQualifiedName~InvalidCustomMethod_Reset|FullyQualifiedName~EmptyMethod_Reset|FullyQualifiedName~KnownOrCustomMethods_Accepted|FullyQualifiedName~CustomMethod_Accepted|FullyQualifiedName~HEADMethod_Accepted|FullyQualifiedName~ConnectMethod_Accepted" --logger "console;verbosity=normal"
dotnet test .\src\Servers\Kestrel\Core\test\Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj --no-restore --filter "FullyQualifiedName~HttpUtilitiesTest|FullyQualifiedName~KnownStringsTests" --logger "console;verbosity=normal"
dotnet test .\src\Servers\Kestrel\test\InMemory.FunctionalTests\InMemory.FunctionalTests.csproj --no-restore --filter "FullyQualifiedName~NonAsciiMethodStart_Reset|FullyQualifiedName~InvalidCustomMethod_Reset|FullyQualifiedName~EmptyMethod_Reset|FullyQualifiedName~KnownOrCustomMethods_Accepted|FullyQualifiedName~CustomMethod_Accepted|FullyQualifiedName~HEADMethod_Accepted|FullyQualifiedName~ConnectMethod_Accepted" --logger "console;verbosity=normal"

Validation uses the in-memory HTTP/2 and HTTP/3 protocol boundary, not external network clients. The full Kestrel suite was not run.

Copilot AI balanced review requested due to automatic review settings November 4, 2026 10:41
@github-actions github-actions Bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Nov 4, 2026

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.

🔵 Needs a closer look

The required frozen head/base source bundle and independent guide-worker results were not supplied, leaving full review gates unverified despite local inspection of the changes.

No open issues 🎉

What changed in this PR

Fixes #70300 by guarding Kestrel’s known-method hash lookup against non-ASCII first characters. Malformed methods now reach the existing validation path instead of throwing an indexing exception, with no public API changes.

Changes:

  • Require an ASCII first character before hashing eligible method strings.
  • Add seven unit cases covering affected lengths and the upper UTF-16 boundary.
  • Add HTTP/2 and HTTP/3 regression tests using UTF-8 headers to check normal stream-level rejection.
File Description
src/​Servers/​Kestrel/​test/​InMemory.FunctionalTests/​Http3/​Http3StreamTests.cs Tests HTTP/3 rejection of non-ASCII method starts.
src/​Servers/​Kestrel/​test/​InMemory.FunctionalTests/​Http2/​Http2StreamTests.cs Tests HTTP/2 rejection of non-ASCII method starts.
src/​Servers/​Kestrel/​Core/​test/​HttpUtilitiesTest.cs Verifies non-ASCII starts return HttpMethod.Custom.
src/​Servers/​Kestrel/​Core/​src/​Internal/​Infrastructure/​HttpUtilities.cs Adds the ASCII guard before method hashing.

Review effort: Balanced

@hoyosjs
hoyosjs merged commit 29ce3d1 into dotnet:main Nov 10, 2026
31 checks passed
@hoyosjs
hoyosjs temporarily deployed to copilot-pat-pool November 10, 2026 09:56 — with GitHub Actions Inactive
@hoyosjs
hoyosjs temporarily deployed to copilot-pat-pool November 10, 2026 09:56 — with GitHub Actions Inactive
@hoyosjs
hoyosjs temporarily deployed to copilot-pat-pool November 10, 2026 09:57 — with GitHub Actions Inactive
@hoyosjs
hoyosjs temporarily deployed to copilot-pat-pool November 10, 2026 09:58 — with GitHub Actions Inactive
@hoyosjs
hoyosjs temporarily deployed to copilot-pat-pool November 10, 2026 09:59 — with GitHub Actions Inactive
@hoyosjs
hoyosjs temporarily deployed to copilot-pat-pool November 10, 2026 10:00 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

✅ No documentation PR was created.

Confidence that documentation is needed: 5%

No docs needed. This is an internal bug fix that restores correct handling of malformed HTTP methods, with no documented behavior change.

Documentation surfaces considered

  • Conceptual article: Not required — Internal bug fix in Kestrel's method hash lookup (HttpUtilities.cs) and tests. No public API changes, and the signals file reports no_signal.
  • Migration guidance: Not required — Upgrading users have nothing to adopt or change.
  • Breaking change: Not required — No API, default, or configuration change. The fix makes malformed methods reach the existing validator instead of throwing.

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — d4038d41 Deployed Nov 10, 2026 by hoyosjs via conclusion #260
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kestrel method pseudoheader parsing throws for short names with non-ASCII starts

3 participants