55using System . Runtime . InteropServices ;
66using Microsoft . AspNetCore . HttpSys . Internal ;
77using Microsoft . Extensions . Logging ;
8+ using static Microsoft . AspNetCore . HttpSys . Internal . HttpApiTypes ;
89
910namespace Microsoft . AspNetCore . Server . HttpSys ;
1011
@@ -16,6 +17,8 @@ internal sealed partial class UrlGroup : IDisposable
1617 Marshal . SizeOf < HttpApiTypes . HTTP_QOS_SETTING_INFO > ( ) ;
1718 private static readonly int RequestPropertyInfoSize =
1819 Marshal . SizeOf < HttpApiTypes . HTTP_BINDING_INFO > ( ) ;
20+ private static readonly int ChannelBindInfoSize =
21+ Marshal . SizeOf < HttpApiTypes . HTTP_CHANNEL_BIND_INFO > ( ) ;
1922
2023 private readonly ILogger _logger ;
2124
@@ -42,6 +45,17 @@ internal unsafe UrlGroup(ServerSession serverSession, RequestQueue requestQueue,
4245
4346 Debug . Assert ( urlGroupId != 0 , "Invalid id returned by HttpCreateUrlGroup" ) ;
4447 Id = urlGroupId ;
48+
49+ if ( AppContext . TryGetSwitch ( "Microsoft.AspNetCore.Server.HttpSys.EnableCBTHardening" , out var enabled ) && enabled )
50+ {
51+ var channelBindingSettings = new HTTP_CHANNEL_BIND_INFO
52+ {
53+ Hardening = HTTP_AUTHENTICATION_HARDENING_LEVELS . HttpAuthenticationHardeningMedium ,
54+ ServiceNames = IntPtr . Zero ,
55+ NumberOfServiceNames = 0 ,
56+ } ;
57+ SetProperty ( HTTP_SERVER_PROPERTY . HttpServerChannelBindProperty , new ( & channelBindingSettings ) , ( uint ) ChannelBindInfoSize ) ;
58+ }
4559 }
4660
4761 internal ulong Id { get ; private set ; }
0 commit comments