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
14 changes: 14 additions & 0 deletions src/Servers/HttpSys/src/NativeInterop/UrlGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.HttpSys.Internal;
using Microsoft.Extensions.Logging;
using static Microsoft.AspNetCore.HttpSys.Internal.HttpApiTypes;

namespace Microsoft.AspNetCore.Server.HttpSys;

Expand All @@ -16,6 +17,8 @@ internal sealed partial class UrlGroup : IDisposable
Marshal.SizeOf<HttpApiTypes.HTTP_QOS_SETTING_INFO>();
private static readonly int RequestPropertyInfoSize =
Marshal.SizeOf<HttpApiTypes.HTTP_BINDING_INFO>();
private static readonly int ChannelBindInfoSize =
Marshal.SizeOf<HttpApiTypes.HTTP_CHANNEL_BIND_INFO>();

private readonly ILogger _logger;

Expand All @@ -42,6 +45,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 = IntPtr.Zero,
NumberOfServiceNames = 0,
};
Comment on lines +51 to +56
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 HTTP_CHANNEL_BIND_INFO struct has a Flags field (see line 666 in HttpApiTypes.cs) that should be set, following the pattern used in other property setters in this class (e.g., SetDelegationProperty, AttachToQueue, SetMaxConnections). Consider setting Flags = (uint)HttpApiTypes.HTTP_FLAGS.HTTP_PROPERTY_FLAG_PRESENT to indicate the property is present.

Copilot uses AI. Check for mistakes.
SetProperty(HTTP_SERVER_PROPERTY.HttpServerChannelBindProperty, new(&channelBindingSettings), (uint)ChannelBindInfoSize);
}
}

internal ulong Id { get; private set; }
Expand Down
18 changes: 16 additions & 2 deletions src/Shared/HttpSys/NativeInterop/HttpApiTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security.Authentication;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -654,6 +652,22 @@ internal struct HTTP_BINDING_INFO
internal IntPtr RequestQueueHandle;
}

internal enum HTTP_AUTHENTICATION_HARDENING_LEVELS
{
HttpAuthenticationHardeningLegacy = 0,
HttpAuthenticationHardeningMedium,
HttpAuthenticationHardeningStrict
}

[StructLayout(LayoutKind.Sequential)]
internal struct HTTP_CHANNEL_BIND_INFO
{
internal HTTP_AUTHENTICATION_HARDENING_LEVELS Hardening;
internal uint Flags;
internal /*PHTTP_SERVICE_BINDING_BASE**/ IntPtr ServiceNames;
internal uint NumberOfServiceNames;
}

[StructLayout(LayoutKind.Sequential)]
internal struct HTTP_CONNECTION_LIMIT_INFO
{
Expand Down
Loading