aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Middleware
diff options
context:
space:
mode:
Diffstat (limited to 'Jellyfin.Server/Middleware')
-rw-r--r--Jellyfin.Server/Middleware/BaseUrlRedirectionMiddleware.cs6
-rw-r--r--Jellyfin.Server/Middleware/ExceptionMiddleware.cs1
-rw-r--r--Jellyfin.Server/Middleware/IpBasedAccessValidationMiddleware.cs4
-rw-r--r--Jellyfin.Server/Middleware/ResponseTimeMiddleware.cs3
-rw-r--r--Jellyfin.Server/Middleware/ServerStartupMessageMiddleware.cs4
5 files changed, 13 insertions, 5 deletions
diff --git a/Jellyfin.Server/Middleware/BaseUrlRedirectionMiddleware.cs b/Jellyfin.Server/Middleware/BaseUrlRedirectionMiddleware.cs
index ae3a3a1c5..9316737bd 100644
--- a/Jellyfin.Server/Middleware/BaseUrlRedirectionMiddleware.cs
+++ b/Jellyfin.Server/Middleware/BaseUrlRedirectionMiddleware.cs
@@ -44,7 +44,11 @@ namespace Jellyfin.Server.Middleware
var localPath = httpContext.Request.Path.ToString();
var baseUrlPrefix = serverConfigurationManager.Configuration.BaseUrl;
- if (!localPath.StartsWith(baseUrlPrefix, StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(localPath, baseUrlPrefix + "/", StringComparison.OrdinalIgnoreCase)
+ || string.Equals(localPath, baseUrlPrefix, StringComparison.OrdinalIgnoreCase)
+ || string.Equals(localPath, "/", StringComparison.OrdinalIgnoreCase)
+ || string.IsNullOrEmpty(localPath)
+ || !localPath.StartsWith(baseUrlPrefix, StringComparison.OrdinalIgnoreCase))
{
// Always redirect back to the default path if the base prefix is invalid or missing
_logger.LogDebug("Normalizing an URL at {LocalPath}", localPath);
diff --git a/Jellyfin.Server/Middleware/ExceptionMiddleware.cs b/Jellyfin.Server/Middleware/ExceptionMiddleware.cs
index 63effafc1..fb1ee3b2b 100644
--- a/Jellyfin.Server/Middleware/ExceptionMiddleware.cs
+++ b/Jellyfin.Server/Middleware/ExceptionMiddleware.cs
@@ -125,6 +125,7 @@ namespace Jellyfin.Server.Middleware
switch (ex)
{
case ArgumentException _: return StatusCodes.Status400BadRequest;
+ case AuthenticationException _:
case SecurityException _: return StatusCodes.Status401Unauthorized;
case DirectoryNotFoundException _:
case FileNotFoundException _:
diff --git a/Jellyfin.Server/Middleware/IpBasedAccessValidationMiddleware.cs b/Jellyfin.Server/Middleware/IpBasedAccessValidationMiddleware.cs
index 59b5fb1ed..4bda8f273 100644
--- a/Jellyfin.Server/Middleware/IpBasedAccessValidationMiddleware.cs
+++ b/Jellyfin.Server/Middleware/IpBasedAccessValidationMiddleware.cs
@@ -32,13 +32,13 @@ namespace Jellyfin.Server.Middleware
/// <returns>The async task.</returns>
public async Task Invoke(HttpContext httpContext, INetworkManager networkManager, IServerConfigurationManager serverConfigurationManager)
{
- if (httpContext.Request.IsLocal())
+ if (httpContext.IsLocal())
{
await _next(httpContext).ConfigureAwait(false);
return;
}
- var remoteIp = httpContext.Request.RemoteIp();
+ var remoteIp = httpContext.GetNormalizedRemoteIp();
if (serverConfigurationManager.Configuration.EnableRemoteAccess)
{
diff --git a/Jellyfin.Server/Middleware/ResponseTimeMiddleware.cs b/Jellyfin.Server/Middleware/ResponseTimeMiddleware.cs
index 3122d92cb..74874da1b 100644
--- a/Jellyfin.Server/Middleware/ResponseTimeMiddleware.cs
+++ b/Jellyfin.Server/Middleware/ResponseTimeMiddleware.cs
@@ -1,6 +1,7 @@
using System.Diagnostics;
using System.Globalization;
using System.Threading.Tasks;
+using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
@@ -69,7 +70,7 @@ namespace Jellyfin.Server.Middleware
_logger.LogWarning(
"Slow HTTP Response from {url} to {remoteIp} in {elapsed:g} with Status Code {statusCode}",
context.Request.GetDisplayUrl(),
- context.Connection.RemoteIpAddress,
+ context.GetNormalizedRemoteIp(),
watch.Elapsed,
context.Response.StatusCode);
}
diff --git a/Jellyfin.Server/Middleware/ServerStartupMessageMiddleware.cs b/Jellyfin.Server/Middleware/ServerStartupMessageMiddleware.cs
index ea81c03a2..2ec063392 100644
--- a/Jellyfin.Server/Middleware/ServerStartupMessageMiddleware.cs
+++ b/Jellyfin.Server/Middleware/ServerStartupMessageMiddleware.cs
@@ -1,3 +1,4 @@
+using System;
using System.Net.Mime;
using System.Threading.Tasks;
using MediaBrowser.Controller;
@@ -34,7 +35,8 @@ namespace Jellyfin.Server.Middleware
IServerApplicationHost serverApplicationHost,
ILocalizationManager localizationManager)
{
- if (serverApplicationHost.CoreStartupHasCompleted)
+ if (serverApplicationHost.CoreStartupHasCompleted
+ || httpContext.Request.Path.Equals("/system/ping", StringComparison.OrdinalIgnoreCase))
{
await _next(httpContext).ConfigureAwait(false);
return;