2020-05-29 09:28:19 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 19:54:44 +00:00
|
|
|
using System;
|
2018-09-12 17:26:21 +00:00
|
|
|
using System.IO;
|
2019-01-13 19:23:38 +00:00
|
|
|
using MediaBrowser.Controller;
|
|
|
|
using MediaBrowser.Controller.Net;
|
2018-09-12 17:26:21 +00:00
|
|
|
using MediaBrowser.Model.IO;
|
2019-01-13 19:23:38 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2018-09-12 17:26:21 +00:00
|
|
|
|
|
|
|
namespace Emby.Server.Implementations
|
|
|
|
{
|
|
|
|
public class ResourceFileManager : IResourceFileManager
|
|
|
|
{
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2020-06-06 00:15:56 +00:00
|
|
|
private readonly ILogger<ResourceFileManager> _logger;
|
2018-09-12 17:26:21 +00:00
|
|
|
|
2019-06-09 22:53:16 +00:00
|
|
|
public ResourceFileManager(ILogger<ResourceFileManager> logger, IFileSystem fileSystem)
|
2018-09-12 17:26:21 +00:00
|
|
|
{
|
2019-06-09 22:53:16 +00:00
|
|
|
_logger = logger;
|
2018-09-12 17:26:21 +00:00
|
|
|
_fileSystem = fileSystem;
|
|
|
|
}
|
|
|
|
|
2019-06-09 22:53:16 +00:00
|
|
|
public string GetResourcePath(string basePath, string virtualPath)
|
2018-09-12 17:26:21 +00:00
|
|
|
{
|
2019-01-26 20:47:11 +00:00
|
|
|
var fullPath = Path.Combine(basePath, virtualPath.Replace('/', Path.DirectorySeparatorChar));
|
2018-09-12 17:26:21 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2019-01-26 20:47:11 +00:00
|
|
|
fullPath = Path.GetFullPath(fullPath);
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2019-06-09 22:53:16 +00:00
|
|
|
_logger.LogError(ex, "Error retrieving full path");
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't allow file system access outside of the source folder
|
|
|
|
if (!_fileSystem.ContainsSubPath(basePath, fullPath))
|
|
|
|
{
|
|
|
|
throw new SecurityException("Access denied");
|
|
|
|
}
|
|
|
|
|
|
|
|
return fullPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|