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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user