Skip to content

Commit d52b491

Browse files
[release9/0] AppContext for HttpSys CBT hardening (#64297)
1 parent a0b083b commit d52b491

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Servers/HttpSys/src/NativeInterop/UrlGroup.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ internal sealed partial class UrlGroup : IDisposable
1818
Marshal.SizeOf<HTTP_QOS_SETTING_INFO>();
1919
private static readonly int RequestPropertyInfoSize =
2020
Marshal.SizeOf<HTTP_BINDING_INFO>();
21+
private static readonly int ChannelBindInfoSize =
22+
Marshal.SizeOf<HTTP_CHANNEL_BIND_INFO>();
2123

2224
private readonly ILogger _logger;
2325

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

4345
Debug.Assert(urlGroupId != 0, "Invalid id returned by HttpCreateUrlGroup");
4446
Id = urlGroupId;
47+
48+
if (AppContext.TryGetSwitch("Microsoft.AspNetCore.Server.HttpSys.EnableCBTHardening", out var enabled) && enabled)
49+
{
50+
var channelBindingSettings = new HTTP_CHANNEL_BIND_INFO
51+
{
52+
Hardening = HTTP_AUTHENTICATION_HARDENING_LEVELS.HttpAuthenticationHardeningMedium,
53+
ServiceNames = (HTTP_SERVICE_BINDING_BASE**)IntPtr.Zero,
54+
NumberOfServiceNames = 0,
55+
};
56+
SetProperty(HTTP_SERVER_PROPERTY.HttpServerChannelBindProperty, new(&channelBindingSettings), (uint)ChannelBindInfoSize);
57+
}
4558
}
4659

4760
internal ulong Id { get; private set; }

src/Servers/HttpSys/src/NativeMethods.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ HTTP_AUTH_EX_FLAG_*
99
HTTP_AUTH_STATUS
1010
HTTP_BINDING_INFO
1111
HTTP_CACHE_POLICY
12+
HTTP_CHANNEL_BIND_INFO
1213
HTTP_CONNECTION_LIMIT_INFO
1314
HTTP_COOKED_URL
1415
HTTP_CREATE_REQUEST_QUEUE_FLAG_*

0 commit comments

Comments
 (0)