From d2a39630060c1303c0d15d4804ebd8571695db83 Mon Sep 17 00:00:00 2001 From: Jonas F Date: Mon, 13 Jan 2025 21:28:01 +0100 Subject: [PATCH] Merge Develop in master (#57) * Merge master in develop (#55) * Fix reachable and IP leak test (#44) * Fix reachable check Fixes failing reachable checks when Basic Authentication is enabled in Sonarr, Radarr, etc. * Add option to disable IP leak test * Revert "Fix reachable and IP leak test (#44)" (#46) This reverts commit 3f5d7bbef35ed7f480d06214cd40aa1334cf1390. * Release 0.6.1 (#48) * Fix typo * Fix typos * Fix typos * Fix typo * Clarify error message * Fix reachable and ipleak test (#47) * Fix reachable check Fixes failing reachable checks when Basic Authentication is enabled in Sonarr, Radarr, etc. * Add option to disable IP leak test --------- Co-authored-by: Jonas F * Add IpLeakTest environment variable to docker compose --------- Co-authored-by: akuntsch * Create Dockerfile.arm64 --------- Co-authored-by: akuntsch * Add configurable cache duration * Make proxy port configurable * Make proxy port configurable * Add API Key auth * Add default settings to appsettings * Fix too many Unauthorized access attempt warnings --------- Co-authored-by: akuntsch --- UmlautAdaptarr/Services/HttpProxyService.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/UmlautAdaptarr/Services/HttpProxyService.cs b/UmlautAdaptarr/Services/HttpProxyService.cs index 7253905..e7f58dd 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; @@ -66,6 +71,7 @@ namespace UmlautAdaptarr.Services await HandleHttp(requestString, clientStream, clientSocket, buffer, bytesRead); } } + private bool ValidateApiKey(string proxyAuthorizationHeader) { // Expect the header to be in the format: "Basic "