1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-22 22:16:13 -04:00

Improve HTTP file mappers

This commit is contained in:
Mark McDowall
2026-02-24 20:13:55 -08:00
parent 028d2414e7
commit f30207c3d1
16 changed files with 94 additions and 33 deletions
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
@@ -16,6 +17,7 @@ namespace Sonarr.Http.Frontend
{
private readonly IEnumerable<IMapHttpRequestsToDisk> _requestMappers;
private readonly Logger _logger;
private static readonly Regex InvalidPathRegex = new (@"([\/\\]|%2f|%5c)\.\.|\.\.([\/\\]|%2f|%5c)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
public StaticResourceController(IEnumerable<IMapHttpRequestsToDisk> requestMappers,
Logger logger)
@@ -50,6 +52,11 @@ namespace Sonarr.Http.Frontend
{
path = "/" + (path ?? "");
if (InvalidPathRegex.IsMatch(path))
{
return NotFound();
}
var mapper = _requestMappers.SingleOrDefault(m => m.CanHandle(path));
if (mapper != null)