Skip to content
Merged
Changes from 1 commit
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
7 changes: 3 additions & 4 deletions src/Servers/Kestrel/Core/src/Internal/AddressBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,17 @@ internal static ListenOptions ParseAddress(string address, out bool https)

return options;

bool IsLocalhost(string host, out string? prefix)
static bool IsLocalhost(string host, out string? prefix)
{
// Check for "localhost"
if (string.Equals(parsedAddress.Host, "localhost", StringComparison.OrdinalIgnoreCase))
if (string.Equals(host, "localhost", StringComparison.OrdinalIgnoreCase))
{
prefix = null;
return true;
}

// Check for use of .localhost TLD (Top Level Domain)
if (host.EndsWith(".localhost", StringComparison.OrdinalIgnoreCase)
&& !string.Equals(parsedAddress.Host, ".localhost", StringComparison.OrdinalIgnoreCase))
if (host.Length > 10 && host.EndsWith(".localhost", StringComparison.OrdinalIgnoreCase))
{
// Take all but the .localhost TLD as the prefix
prefix = host[..^10]; // 10 is the length of ".localhost"
Expand Down
Loading