From 9eabb73b777a59e75705b83a17968cc1f0ed4a1d Mon Sep 17 00:00:00 2001 From: Andrey Surkov Date: Thu, 19 Sep 2024 12:12:54 +0400 Subject: [PATCH 1/4] Skip processing of media root path --- .../Services/MediaFileStoreResolverMiddleware.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs b/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs index ed3938b8d7e..abeb823ccaf 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using OrchardCore.FileStorage; using OrchardCore.Routing; namespace OrchardCore.Media.Services; @@ -50,13 +51,14 @@ public async Task Invoke(HttpContext context) } var validatePath = context.Request.Path.StartsWithNormalizedSegments(_assetsRequestPath, StringComparison.OrdinalIgnoreCase, out var subPath); - if (!validatePath) + if (!validatePath || string.IsNullOrEmpty(_mediaFileStore.NormalizePath(subPath))) { _logger.LogDebug("Request path {Path} does not match the assets request path {RequestPath}", subPath, _assetsRequestPath); await _next(context); return; } + // subPath.Value returns an unescaped path value, subPath returns an escaped path value. var subPathValue = subPath.Value; From e9018ca4e21c9e9492c9d0c00a1fd5fa6fa0d362 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Thu, 19 Sep 2024 14:56:02 +0300 Subject: [PATCH 2/4] Update src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs --- .../Services/MediaFileStoreResolverMiddleware.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs b/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs index abeb823ccaf..a437c7b33e1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs @@ -58,7 +58,6 @@ public async Task Invoke(HttpContext context) return; } - // subPath.Value returns an unescaped path value, subPath returns an escaped path value. var subPathValue = subPath.Value; From 3457579d1b6ed46ee2cce2c349fda6f1bd601eff Mon Sep 17 00:00:00 2001 From: Andrey Surkov Date: Fri, 20 Sep 2024 12:06:57 +0400 Subject: [PATCH 3/4] Remove useless debug message --- .../Services/MediaFileStoreResolverMiddleware.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs b/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs index a437c7b33e1..662294e399b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs @@ -53,7 +53,6 @@ public async Task Invoke(HttpContext context) var validatePath = context.Request.Path.StartsWithNormalizedSegments(_assetsRequestPath, StringComparison.OrdinalIgnoreCase, out var subPath); if (!validatePath || string.IsNullOrEmpty(_mediaFileStore.NormalizePath(subPath))) { - _logger.LogDebug("Request path {Path} does not match the assets request path {RequestPath}", subPath, _assetsRequestPath); await _next(context); return; } From 39f9234ed78b5fa8c07e81a501e7331156267f86 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Fri, 20 Sep 2024 15:22:18 +0300 Subject: [PATCH 4/4] Update src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs --- .../Services/MediaFileStoreResolverMiddleware.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs b/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs index 662294e399b..66be3edd3a4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Services/MediaFileStoreResolverMiddleware.cs @@ -54,6 +54,7 @@ public async Task Invoke(HttpContext context) if (!validatePath || string.IsNullOrEmpty(_mediaFileStore.NormalizePath(subPath))) { await _next(context); + return; }