Skip to content

Conversation

DeagleGross
Copy link
Member

Fix HTTP.SYS parsing the port values out of native structure

As correctly mentioned in the issue, possible TCP port numbers should be in range from 0 to 65535 as per RFC.

However, if running a sample aspnetcore app with HTTP.SYS and listening on high-value port (for example 42000), IHttpConnectionFeature reports negative values for LocalPort / RemotePort (if client has high value port as well).

I am proposing a fix to HttpSys.Internal SocketAddress implementation (both ipv4 and ipv6) where value coming from the native struct is basically following the IPAddress.NetworkToHostOrder() implementation. The difference is that IPAddress.NetworkToHostOrder() does not return ushort and therefore does the incorrect conversion.

Added tests to make sure SocketAddressIPv4 and SocketAddressIPv6 correctly parse different values.

Fixes #62128

@DeagleGross DeagleGross self-assigned this Jun 30, 2025
@github-actions github-actions bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Jun 30, 2025
@DeagleGross DeagleGross enabled auto-merge (squash) June 30, 2025 17:59
@DeagleGross DeagleGross merged commit 8f2c205 into main Jun 30, 2025
27 of 28 checks passed
@DeagleGross DeagleGross deleted the dmkorolev/httpsys-port branch June 30, 2025 20:36
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview7 milestone Jun 30, 2025
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.

HTTP Connection RemotePort and LocalPort values are incorrect for HttpSys
3 participants