Skip to content

Fix ALPN protocol list size field type and add boundary tests#124590

Draft
rzikm wants to merge 2 commits intodotnet:mainfrom
rzikm:fix/sslstream-alpn-size-validation
Draft

Fix ALPN protocol list size field type and add boundary tests#124590
rzikm wants to merge 2 commits intodotnet:mainfrom
rzikm:fix/sslstream-alpn-size-validation

Conversation

@rzikm
Copy link
Member

@rzikm rzikm commented Feb 19, 2026

Summary

Fix Sec_Application_Protocols.ProtocolListSize field type from short to ushort to match the native Windows SEC_APPLICATION_PROTOCOL_LIST struct (USHORT), and add tests for ALPN list size validation.

Changes

Bug fix

  • Interop.Sec_Application_Protocols.cs: Changed ProtocolListSize from short to ushort and updated the aggregate size limit from short.MaxValue (32,767) to ushort.MaxValue (65,535), aligning with both the native Windows API and the RFC 7301 TLS wire format.

Tests

  • SslStreamAlpnTests.cs: Added SslStream_StreamToStream_AlpnListTotalSizeExceedsLimit_Throws — verifies that exceeding the 65,535-byte aggregate ALPN list limit throws:
    • ArgumentException on Windows (managed validation in GetProtocolLength())
    • AuthenticationException on Linux/FreeBSD (OpenSSL fails during ClientHello construction)
  • SslApplicationProtocolTests.cs: Added boundary tests for individual protocol sizes (0, 1, 254, 255, 256, 512 bytes) via both byte[] and string constructors.

- Change Sec_Application_Protocols.ProtocolListSize from short to ushort
  to match the native Windows SEC_APPLICATION_PROTOCOL_LIST struct (USHORT)
- Update aggregate size limit from short.MaxValue (32,767) to
  ushort.MaxValue (65,535), aligning with RFC 7301 wire format
- Add functional test for oversized ALPN list (Windows and Unix paths)
- Add unit tests for individual protocol size boundaries

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 19, 2026 12:28
@rzikm rzikm marked this pull request as draft February 19, 2026 12:29
@dotnet-policy-service
Copy link
Contributor

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

Copy link
Contributor

Copilot AI left a comment

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 fixes a type mismatch in the Windows SChannel interop layer where Sec_Application_Protocols.ProtocolListSize was incorrectly defined as short instead of ushort, aligning it with the native Windows SEC_APPLICATION_PROTOCOL_LIST structure and RFC 7301 specifications. The fix increases the maximum aggregate ALPN list size from 32,767 to 65,535 bytes and adds comprehensive tests to validate both individual protocol size limits and aggregate list size limits.

Changes:

  • Fixed ProtocolListSize field type from short to ushort in the Windows SChannel interop struct
  • Updated aggregate ALPN list size validation limit from short.MaxValue (32,767) to ushort.MaxValue (65,535)
  • Added unit tests for individual protocol size boundaries (0, 1, 254, 255, 256, 512 bytes)
  • Added functional test verifying aggregate ALPN list size limit enforcement with platform-specific exception handling

Reviewed changes

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

File Description
Interop.Sec_Application_Protocols.cs Changed ProtocolListSize field from short to ushort and updated all casts and comparisons to use ushort.MaxValue instead of short.MaxValue
SslApplicationProtocolTests.cs Added two theory-based boundary tests for individual protocol size validation via both byte array and string constructors
SslStreamAlpnTests.cs Added functional test for aggregate ALPN list size limit, verifying ArgumentException on Windows and AuthenticationException on Linux/FreeBSD

- Add ushort.MaxValue aggregate size check to Unix (OpenSSL) path
- Add ushort.MaxValue aggregate size check to macOS (Network.framework
  and SecureTransport) paths
- Add ushort.MaxValue aggregate size check to Android path
- All platforms now consistently throw ArgumentException for oversized
  ALPN lists, matching the RFC 7301 wire format limit
- Simplify test to assert ArgumentException on all platforms

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant

Comments