CVE-2021-23415 (published 2021-07-28T16:15Z)

This affects the package elFinder.AspNet before 1.1.1. The user-controlled file name is not properly sanitized before it is used to create a file system path.

Severity: MEDIUM
CVSS v2 base score: 5.0 (AV:N/AC:L/Au:N/C:P/I:N/A:N)
CVSS v3 base score: 7.5, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N)

Weakness information:
cwe_id: CWE-22
cwe_name: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
description: The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.
extended_description: 
            Many file operations are intended to take place within a restricted directory. By using special elements such as ".." and "/" separators, attackers can escape outside of the restricted location to access files or directories that are elsewhere on the system. One of the most common special elements is the "../" sequence, which in most modern operating systems is interpreted as the parent directory of the current location. This is referred to as relative path traversal. Path traversal also covers the use of absolute pathnames such as "/usr/local/bin" to access unexpected files. This is referred to as absolute path traversal.
         
         

Fix information:
repo_url: https://github.com/mguinness/elFinder.AspNet
commit_details: repo_url: https://github.com/mguinness/elFinder.AspNet
author: mguinness
author_date: 2021-07-09 18:28:34-07:00
msg: Directory traversal fixes
repository: repo_url: https://github.com/mguinness/elFinder.AspNet
repo_name: mguinness/elFinder.AspNet
description: elFinder ASP.NET backend
repo_language: CSS
owner: mguinness
file_changes: filename: FileSystemDriver.cs
change_type: ModificationType.MODIFY
diff: @@ -229,6 +229,12 @@ namespace elFinder.AspNet.Drivers.FileSystem
                         string file = Path.Combine(rootPath, entry.FullName)
                              .Replace("/", separator).Replace("\\", separator);
 
+                        string destPath = Path.GetFullPath(file);
+                        if (!destPath.StartsWith(rootPath, StringComparison.OrdinalIgnoreCase))
+                        {
+                            throw new NotSupportedException($"Entry '{entry.FullName}' is outside of the destination directory.");
+                        }
+
                         if (file.EndsWith(separator)) //directory
                         {
                             var dir = new FileSystemDirectory(file);
@@ -636,12 +642,22 @@ namespace elFinder.AspNet.Drivers.FileSystem
             if (path.IsDirectory)
             {
                 var newPath = new FileSystemDirectory(Path.Combine(path.Directory.Parent.FullName, name));
+                string destPath = Path.GetFullPath(newPath.FullName);
+                if (!destPath.StartsWith(path.RootVolume.RootDirectory, StringComparison.OrdinalIgnoreCase))
+                {
+                    throw new NotSupportedException($"Entry '{name}' is outside of the home directory.");
+                }
                 Directory.Move(path.Directory.FullName, newPath.FullName);
                 response.Added.Add(await BaseModel.CreateAsync(newPath, path.RootVolume));
             }
             else
             {
                 var newPath = new FileSystemFile(Path.Combine(path.File.DirectoryName, name));
+                string destPath = Path.GetFullPath(newPath.FullName);
+                if (!destPath.StartsWith(path.RootVolume.RootDirectory, StringComparison.OrdinalIgnoreCase))
+                {
+                    throw new NotSupportedException($"Entry '{name}' is outside of the home directory.");
+                }
                 File.Move(path.File.FullName, newPath.FullName);
                 response.Added.Add(await BaseModel.CreateAsync(newPath, path.RootVolume));
             }

programming_language: C#