From ed044e9a59699618a87543a8ac9d8de63782450f Mon Sep 17 00:00:00 2001 From: pcjones Date: Mon, 13 Jan 2025 21:26:24 +0100 Subject: [PATCH] Fix too many Unauthorized access attempt warnings --- UmlautAdaptarr/Services/HttpProxyService.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/UmlautAdaptarr/Services/HttpProxyService.cs b/UmlautAdaptarr/Services/HttpProxyService.cs index 7253905..1e1c640 100644 --- a/UmlautAdaptarr/Services/HttpProxyService.cs +++ b/UmlautAdaptarr/Services/HttpProxyService.cs @@ -45,10 +45,15 @@ namespace UmlautAdaptarr.Services if (_options.ApiKey != null) { var headers = ParseHeaders(buffer, bytesRead); + if (!headers.TryGetValue("Proxy-Authorization", out var 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")); clientSocket.Close(); return;