Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Servers/HttpSys/src/NativeInterop/UrlGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ internal sealed partial class UrlGroup : IDisposable
Marshal.SizeOf<HTTP_QOS_SETTING_INFO>();
private static readonly int RequestPropertyInfoSize =
Marshal.SizeOf<HTTP_BINDING_INFO>();
private static readonly int ChannelBindInfoSize =
Marshal.SizeOf<HTTP_CHANNEL_BIND_INFO>();

private readonly ILogger _logger;

Expand All @@ -42,6 +44,17 @@ internal unsafe UrlGroup(ServerSession serverSession, RequestQueue requestQueue,

Debug.Assert(urlGroupId != 0, "Invalid id returned by HttpCreateUrlGroup");
Id = urlGroupId;

if (AppContext.TryGetSwitch("Microsoft.AspNetCore.Server.HttpSys.EnableCBTHardening", out var enabled) && enabled)
{
var channelBindingSettings = new HTTP_CHANNEL_BIND_INFO
{
Hardening = HTTP_AUTHENTICATION_HARDENING_LEVELS.HttpAuthenticationHardeningMedium,
ServiceNames = (HTTP_SERVICE_BINDING_BASE**)IntPtr.Zero,
NumberOfServiceNames = 0,
};
SetProperty(HTTP_SERVER_PROPERTY.HttpServerChannelBindProperty, new(&channelBindingSettings), (uint)ChannelBindInfoSize);
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

The SetProperty call in the constructor should handle potential errors. If this call fails, the UrlGroup is still constructed but without CBT hardening, which could lead to a silent security configuration failure. Consider adding error handling or logging similar to other property setters in this class, or document that failures are intentionally ignored during construction.

Suggested change
SetProperty(HTTP_SERVER_PROPERTY.HttpServerChannelBindProperty, new(&channelBindingSettings), (uint)ChannelBindInfoSize);
try
{
SetProperty(HTTP_SERVER_PROPERTY.HttpServerChannelBindProperty, new(&channelBindingSettings), (uint)ChannelBindInfoSize);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to set CBT hardening on UrlGroup during construction. Security configuration may be incomplete.");
// Optionally, rethrow or handle as needed for your application's security requirements.
}

Copilot uses AI. Check for mistakes.
}
}

internal ulong Id { get; private set; }
Expand Down
1 change: 1 addition & 0 deletions src/Servers/HttpSys/src/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ HTTP_AUTH_EX_FLAG_*
HTTP_AUTH_STATUS
HTTP_BINDING_INFO
HTTP_CACHE_POLICY
HTTP_CHANNEL_BIND_INFO
HTTP_CONNECTION_LIMIT_INFO
HTTP_COOKED_URL
HTTP_CREATE_REQUEST_QUEUE_FLAG_*
Expand Down
Loading