From adb0837dc219df6f9474d819c68a73f8c3decf48 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Sat, 6 Jan 2024 14:43:19 -0700 Subject: [PATCH 1/2] Respond with Service Unavailable if not in correct network --- Jellyfin.Api/Middleware/IpBasedAccessValidationMiddleware.cs | 2 ++ Jellyfin.Api/Middleware/LanFilteringMiddleware.cs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Jellyfin.Api/Middleware/IpBasedAccessValidationMiddleware.cs b/Jellyfin.Api/Middleware/IpBasedAccessValidationMiddleware.cs index 27bcd5570..0d107d11b 100644 --- a/Jellyfin.Api/Middleware/IpBasedAccessValidationMiddleware.cs +++ b/Jellyfin.Api/Middleware/IpBasedAccessValidationMiddleware.cs @@ -41,6 +41,8 @@ public class IPBasedAccessValidationMiddleware if (!networkManager.HasRemoteAccess(remoteIP)) { + // No access from network, respond with 503 instead of 200. + httpContext.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable; return; } diff --git a/Jellyfin.Api/Middleware/LanFilteringMiddleware.cs b/Jellyfin.Api/Middleware/LanFilteringMiddleware.cs index d8c95ddff..34ed4818f 100644 --- a/Jellyfin.Api/Middleware/LanFilteringMiddleware.cs +++ b/Jellyfin.Api/Middleware/LanFilteringMiddleware.cs @@ -1,3 +1,4 @@ +using System.Net; using System.Threading.Tasks; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; @@ -40,6 +41,8 @@ public class LanFilteringMiddleware var host = httpContext.GetNormalizedRemoteIP(); if (!networkManager.IsInLocalNetwork(host)) { + // No access from network, respond with 503 instead of 200. + httpContext.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable; return; } From fa0413d6e4ec565fd039a99ead3b73391046f222 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Sat, 6 Jan 2024 15:24:17 -0700 Subject: [PATCH 2/2] Use StatusCodes which is already an int --- Jellyfin.Api/Middleware/IpBasedAccessValidationMiddleware.cs | 2 +- Jellyfin.Api/Middleware/LanFilteringMiddleware.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Jellyfin.Api/Middleware/IpBasedAccessValidationMiddleware.cs b/Jellyfin.Api/Middleware/IpBasedAccessValidationMiddleware.cs index 0d107d11b..842a69dd9 100644 --- a/Jellyfin.Api/Middleware/IpBasedAccessValidationMiddleware.cs +++ b/Jellyfin.Api/Middleware/IpBasedAccessValidationMiddleware.cs @@ -42,7 +42,7 @@ public class IPBasedAccessValidationMiddleware if (!networkManager.HasRemoteAccess(remoteIP)) { // No access from network, respond with 503 instead of 200. - httpContext.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable; + httpContext.Response.StatusCode = StatusCodes.Status503ServiceUnavailable; return; } diff --git a/Jellyfin.Api/Middleware/LanFilteringMiddleware.cs b/Jellyfin.Api/Middleware/LanFilteringMiddleware.cs index 34ed4818f..35b0a1dd0 100644 --- a/Jellyfin.Api/Middleware/LanFilteringMiddleware.cs +++ b/Jellyfin.Api/Middleware/LanFilteringMiddleware.cs @@ -42,7 +42,7 @@ public class LanFilteringMiddleware if (!networkManager.IsInLocalNetwork(host)) { // No access from network, respond with 503 instead of 200. - httpContext.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable; + httpContext.Response.StatusCode = StatusCodes.Status503ServiceUnavailable; return; }