Skip to content

fix: rejection host header validation scenarios #2091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
96b2545
try
DeagleGross May 7, 2025
4b3ed06
configure host
DeagleGross May 8, 2025
d1c1723
http client
DeagleGross May 8, 2025
1408edb
push log
DeagleGross May 8, 2025
bfb3fdb
tmp enable logging
DeagleGross May 8, 2025
4b83f54
and microsoft logging enable
DeagleGross May 8, 2025
75ee7de
we dont need httpS here?
DeagleGross May 8, 2025
2289f92
back to https due to server setup
DeagleGross May 8, 2025
a2aa6e7
no logging
DeagleGross May 8, 2025
1b8ae84
definitely invalid encoded url
DeagleGross May 12, 2025
0af56a4
httpclient for http.sys jobs
DeagleGross May 12, 2025
d5a9511
try with 2048 public key length explicitly
DeagleGross May 12, 2025
22165b3
try logging
DeagleGross May 13, 2025
3711bbd
this?
DeagleGross May 13, 2025
8b697b8
for debug
DeagleGross May 13, 2025
64d7d5d
set url prefixes
DeagleGross May 14, 2025
aa7349a
log host
DeagleGross May 14, 2025
65cf5dc
fix
DeagleGross May 14, 2025
59afb4a
enable htpt.sys hostname!
DeagleGross May 14, 2025
bf8b9d4
cover enable host validation for kestrel
DeagleGross May 14, 2025
52feb62
try with full message
DeagleGross May 14, 2025
c4ba140
review
DeagleGross May 14, 2025
096d307
Merge branch 'main' into dmkorolev/rejection
DeagleGross May 14, 2025
0503a38
try ith other hostname
DeagleGross May 14, 2025
4e0b7b8
Merge branch 'dmkorolev/rejection' of https://github.com/DeagleGross/…
DeagleGross May 14, 2025
de2c192
try wrk
DeagleGross May 20, 2025
45ce05a
comment out for test
DeagleGross May 20, 2025
c4382aa
back
DeagleGross May 20, 2025
a1424ab
review
DeagleGross May 20, 2025
fc06504
try wrk2?
DeagleGross May 20, 2025
8ad0658
no wrk2
DeagleGross May 20, 2025
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
Prev Previous commit
Next Next commit
configure host
  • Loading branch information
DeagleGross committed May 8, 2025
commit 4b3ed0616ce73ca6a81e756d992216e4d8dba938
2 changes: 0 additions & 2 deletions src/BenchmarksApps/TLS/Kestrel/Kestrel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
</ItemGroup>

<ItemGroup>
<Folder Include="certificates\" />

<None Include="..\Certificates\2048\testCert-2048.pfx" Link="certificates\testCert-2048.pfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
33 changes: 25 additions & 8 deletions src/BenchmarksApps/TLS/Kestrel/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Diagnostics;
using System.Net;
using System.Net.Security;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using Microsoft.AspNetCore.Authentication.Certificate;
using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.HttpSys;
Expand Down Expand Up @@ -39,6 +38,20 @@
var connectionIds = new HashSet<string>();
var fetchedCertsCounter = 0;

builder.Services.Configure<Microsoft.AspNetCore.HostFiltering.HostFilteringOptions>(options =>
{
var allowedHosts = new HashSet<string>();
foreach (var endpoint in listeningEndpoints.Split([';'], StringSplitOptions.RemoveEmptyEntries))
{
var urlPrefix = UrlPrefix.Create(endpoint);
allowedHosts.Add(urlPrefix.Host);
}

options.AllowedHosts = allowedHosts.ToArray();
options.IncludeFailureMessage = false; // Suppress the failure message in response body
options.AllowEmptyHosts = true;
});

builder.WebHost.UseKestrel(options =>
{
foreach (var value in listeningEndpoints.Split([';'], StringSplitOptions.RemoveEmptyEntries))
Expand All @@ -56,14 +69,16 @@ void ConfigureListen(KestrelServerOptions serverOptions, IConfigurationRoot conf
var certificatePath = Path.Combine("certificates", $"testCert-{certPublicKeyLength}.pfx");
Console.WriteLine($"Using certificate: {certificatePath}");

var certPath =
#if DEBUG
Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)!, certificatePath); // exe location
#else
certificatePath;
#endif

// [SuppressMessage("Microsoft.Security", "CSCAN0220.DefaultPasswordContexts", Justification="Benchmark code, not a secret")]
listenOptions.UseHttps(certificatePath, "testPassword", options =>
listenOptions.UseHttps(certPath, "testPassword", options =>
{
options.OnAuthenticate = (ctx, authOptions) =>
{
Console.WriteLine("Established connection " + ctx.ConnectionId);
};

if (supportedTlsVersions is not null)
{
options.SslProtocols = supportedTlsVersions.Value;
Expand Down Expand Up @@ -103,6 +118,8 @@ void ConfigureListen(KestrelServerOptions serverOptions, IConfigurationRoot conf

var app = builder.Build();

app.UseHostFiltering();

bool AllowAnyCertificateValidationWithLogging(X509Certificate2 certificate, X509Chain? chain, SslPolicyErrors errors)
{
fetchedCertsCounter++;
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarksApps/TLS/Kestrel/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
}
},
"mTLS": "false",
"tlsRenegotiation": "true",
"certValidationConsoleEnabled": "true"
"tlsRenegotiation": "false",
"certValidationConsoleEnabled": "false"
}
3 changes: 1 addition & 2 deletions src/BenchmarksApps/TLS/Kestrel/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
}