2
0

ResourceFileManager.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.IO;
  3. using MediaBrowser.Controller;
  4. using MediaBrowser.Controller.Net;
  5. using MediaBrowser.Model.IO;
  6. using Microsoft.Extensions.Logging;
  7. namespace Emby.Server.Implementations
  8. {
  9. public class ResourceFileManager : IResourceFileManager
  10. {
  11. private readonly IFileSystem _fileSystem;
  12. private readonly ILogger _logger;
  13. public ResourceFileManager(ILogger<ResourceFileManager> logger, IFileSystem fileSystem)
  14. {
  15. _logger = logger;
  16. _fileSystem = fileSystem;
  17. }
  18. public string GetResourcePath(string basePath, string virtualPath)
  19. {
  20. var fullPath = Path.Combine(basePath, virtualPath.Replace('/', Path.DirectorySeparatorChar));
  21. try
  22. {
  23. fullPath = Path.GetFullPath(fullPath);
  24. }
  25. catch (Exception ex)
  26. {
  27. _logger.LogError(ex, "Error retrieving full path");
  28. }
  29. // Don't allow file system access outside of the source folder
  30. if (!_fileSystem.ContainsSubPath(basePath, fullPath))
  31. {
  32. throw new SecurityException("Access denied");
  33. }
  34. return fullPath;
  35. }
  36. }
  37. }