jellyfin/Emby.Server.Implementations/ResourceFileManager.cs

44 lines
1.2 KiB
C#
Raw Normal View History

using System;
2018-09-12 10:26:21 -07:00
using System.IO;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Net;
2018-09-12 10:26:21 -07:00
using MediaBrowser.Model.IO;
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
{
var fullPath = Path.Combine(basePath, virtualPath.Replace('/', Path.DirectorySeparatorChar));
2018-09-12 10:26:21 -07:00
try
{
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;
}
}
}