Explorar o código

Prevent directory browsing

Luke Pulverenti %!s(int64=10) %!d(string=hai) anos
pai
achega
dca5101e46
Modificáronse 1 ficheiros con 11 adicións e 1 borrados
  1. 11 1
      MediaBrowser.WebDashboard/Api/PackageCreator.cs

+ 11 - 1
MediaBrowser.WebDashboard/Api/PackageCreator.cs

@@ -102,7 +102,17 @@ namespace MediaBrowser.WebDashboard.Api
         /// <returns>System.String.</returns>
         private string GetDashboardResourcePath(string virtualPath)
         {
-            return Path.Combine(DashboardUIPath, virtualPath.Replace('/', Path.DirectorySeparatorChar));
+            var rootPath = DashboardUIPath;
+
+            var fullPath = Path.Combine(rootPath, virtualPath.Replace('/', Path.DirectorySeparatorChar));
+
+            // Don't allow file system access outside of the source folder
+            if (!_fileSystem.ContainsSubPath(rootPath, fullPath))
+            {
+                throw new UnauthorizedAccessException();
+            }
+
+            return fullPath;
         }
 
         /// <summary>