Fix too many Unauthorized access attempt warnings

This commit is contained in:
pcjones
2025-01-13 21:26:24 +01:00
parent dd6b4c9d3b
commit ed044e9a59

View File

@@ -45,10 +45,15 @@ namespace UmlautAdaptarr.Services
if (_options.ApiKey != null) if (_options.ApiKey != null)
{ {
var headers = ParseHeaders(buffer, bytesRead); var headers = ParseHeaders(buffer, bytesRead);
if (!headers.TryGetValue("Proxy-Authorization", out var proxyAuthorizationHeader) || if (!headers.TryGetValue("Proxy-Authorization", out var proxyAuthorizationHeader) ||
!ValidateApiKey(proxyAuthorizationHeader)) !ValidateApiKey(proxyAuthorizationHeader))
{ {
_logger.LogWarning("Unauthorized access attempt."); var isFirstRequest = !headers.ContainsKey("Proxy-Authorization");
if (!isFirstRequest)
{
_logger.LogWarning("Unauthorized access attempt.");
}
await clientStream.WriteAsync(Encoding.ASCII.GetBytes("HTTP/1.1 407 Proxy Authentication Required\r\nProxy-Authenticate: Basic realm=\"Proxy\"\r\n\r\n")); await clientStream.WriteAsync(Encoding.ASCII.GetBytes("HTTP/1.1 407 Proxy Authentication Required\r\nProxy-Authenticate: Basic realm=\"Proxy\"\r\n\r\n"));
clientSocket.Close(); clientSocket.Close();
return; return;