improve validation in package extraction
This commit is contained in:
parent
73781c7edb
commit
8cd6a72dd3
|
@ -197,6 +197,12 @@ namespace Oqtane.Infrastructure
|
||||||
string[] segments = entry.FullName.Split('/'); // ZipArchiveEntries always use unix path separator
|
string[] segments = entry.FullName.Split('/'); // ZipArchiveEntries always use unix path separator
|
||||||
string filename = Path.Combine(folder, string.Join(Path.DirectorySeparatorChar, segments, ignoreLeadingSegments, segments.Length - ignoreLeadingSegments));
|
string filename = Path.Combine(folder, string.Join(Path.DirectorySeparatorChar, segments, ignoreLeadingSegments, segments.Length - ignoreLeadingSegments));
|
||||||
|
|
||||||
|
// validate path to prevent path traversal
|
||||||
|
if (!Path.GetFullPath(filename).StartsWith(folder + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(Path.GetDirectoryName(filename)))
|
if (!Directory.Exists(Path.GetDirectoryName(filename)))
|
||||||
|
@ -227,6 +233,7 @@ namespace Oqtane.Infrastructure
|
||||||
// an error occurred extracting the file
|
// an error occurred extracting the file
|
||||||
filename = "";
|
filename = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user