Skip to content

Limit the size of SNI parsed from ClientHello - #133361

Merged
rzikm merged 1 commit into
dotnet:mainfrom
rzikm:rzikm/limit-clienthello-sni-size
Sep 8, 2026
Merged

rzikm merged 1 commit into
dotnet:mainfrom
rzikm:rzikm/limit-clienthello-sni-size

Conversation

@rzikm

@rzikm rzikm commented Sep 7, 2026

Copy link
Copy Markdown
Member

ClientHello SNI payloads carry a 16-bit length, but DNS hostnames are limited to 255 encoded bytes. Decoding larger peer-controlled values creates unnecessary managed strings for malformed input.

Cap managed SNI decoding at 255 bytes and treat larger values as unavailable SNI. The frame remains classified as complete so TlsSession does not incorrectly wait for more input. Boundary tests cover accepted 255-byte and rejected 256-byte payloads, including frame-completeness behavior.

Tests:

  • TlsFrameHelperTests: 4,060 passed
  • System.Net.Security.Unit.Tests: 117 passed, 4 skipped

Fixes: #133348

Note

This pull request description was generated by GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 7, 2026 15:20
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 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: @dotnet/ncl, @bartonjs, @vcsjones
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.

🟢 Approval recommended

The behavioral change is narrowly scoped, preserves frame completeness semantics, and is covered by targeted boundary tests.

Pull request overview

This PR hardens System.Net.Security TLS ClientHello parsing by capping Server Name Indication (SNI) hostname decoding at 255 bytes, avoiding unnecessary managed string allocations for malformed / oversized peer input while still treating the TLS frame as complete.

Changes:

  • Add a 255-byte maximum for SNI hostname decoding during ClientHello parsing (TlsFrameHelper), returning null SNI when exceeded.
  • Add boundary coverage for 255-byte (accepted) and 256-byte (rejected) SNI payloads in TlsFrameHelperTests, including ensuring TryGetFrameInfo still returns true (frame complete).
File summaries
File Description
src/libraries/System.Net.Security/src/System/Net/Security/TlsFrameHelper.cs Adds a maximum-length guard to skip SNI decoding for oversized hostnames while keeping parsing successful.
src/libraries/System.Net.Security/tests/FunctionalTests/TlsFrameHelperTests.cs Adds tests and a helper to generate ClientHello frames validating 255/256-byte SNI behavior and frame completeness.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

@rzikm

rzikm commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

/ba-g Test failures are unrelated

@rzikm
rzikm merged commit 01d61a5 into dotnet:main Sep 8, 2026
81 of 83 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 9, 2026
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.

Limit the size of SNI parsed from ClientHello

4 participants