This commit is contained in:
Chris Ross (ASP.NET) 2018-09-17 15:34:32 -07:00
Родитель 7f348c4e0f 4a4dde182f
Коммит 2a731baaa3
2 изменённых файлов: 13 добавлений и 12 удалений

Просмотреть файл

@ -102,7 +102,11 @@ namespace Microsoft.AspNetCore.HostFiltering
throw new InvalidOperationException("No allowed hosts were configured.");
}
_logger.LogDebug("Allowed hosts: " + string.Join("; ", allowedHosts));
if (_logger.IsEnabled(LogLevel.Debug))
{
_logger.LogDebug("Allowed hosts: {Hosts}", string.Join("; ", allowedHosts));
}
_allowedHosts = allowedHosts;
return _allowedHosts;
}
@ -148,29 +152,26 @@ namespace Microsoft.AspNetCore.HostFiltering
// Http/1.1 requires the header but the value may be empty.
if (!_options.AllowEmptyHosts)
{
_logger.LogInformation($"{context.Request.Protocol} request rejected due to missing or empty host header.");
_logger.LogInformation("{Protocol} request rejected due to missing or empty host header.", context.Request.Protocol);
return false;
}
if (_logger.IsEnabled(LogLevel.Debug))
{
_logger.LogDebug($"{context.Request.Protocol} request allowed with missing or empty host header.");
}
_logger.LogDebug("{Protocol} request allowed with missing or empty host header.", context.Request.Protocol);
return true;
}
if (_allowAnyNonEmptyHost == true)
{
_logger.LogTrace($"All hosts are allowed.");
_logger.LogTrace("All hosts are allowed.");
return true;
}
if (HostString.MatchesAny(host, allowedHosts))
{
_logger.LogTrace($"The host '{host}' matches an allowed host.");
_logger.LogTrace("The host '{Host}' matches an allowed host.", host);
return true;
}
_logger.LogInformation($"The host '{host}' does not match an allowed host.");
_logger.LogInformation("The host '{Host}' does not match an allowed host.", host);
return false;
}
}

Просмотреть файл

@ -233,7 +233,7 @@ namespace Microsoft.AspNetCore.HttpOverrides
if (currentValues.RemoteIpAndPort != null && checkKnownIps && !CheckKnownAddress(currentValues.RemoteIpAndPort.Address))
{
// Stop at the first unknown remote IP, but still apply changes processed so far.
_logger.LogDebug(1, $"Unknown proxy: {currentValues.RemoteIpAndPort}");
_logger.LogDebug(1, "Unknown proxy: {RemoteIpAndPort}", currentValues.RemoteIpAndPort);
break;
}
@ -248,12 +248,12 @@ namespace Microsoft.AspNetCore.HttpOverrides
else if (!string.IsNullOrEmpty(set.IpAndPortText))
{
// Stop at the first unparsable IP, but still apply changes processed so far.
_logger.LogDebug(1, $"Unparsable IP: {set.IpAndPortText}");
_logger.LogDebug(1, "Unparsable IP: {IpAndPortText}", set.IpAndPortText);
break;
}
else if (_options.RequireHeaderSymmetry)
{
_logger.LogWarning(2, $"Missing forwarded IPAddress.");
_logger.LogWarning(2, "Missing forwarded IPAddress.");
return;
}
}