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