Skip to content

Commit 4f10a54

Browse files
committed
Try to detect leaky zips
1 parent 3a20e7a commit 4f10a54

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Paket.Core/Dependencies/NuGetCache.fs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,11 +534,26 @@ let ExtractPackage(fileName:string, targetFolder, packageName:PackageName, versi
534534
with
535535
| exn ->
536536
try
537+
let target = FileInfo(targetFolder).FullName |> normalizePath
537538
traceWarnfn "Package couldn't be extracted to %s. Message: %s. Trying to extract files individually." targetFolder exn.Message
538539
use archive = ZipFile.OpenRead fileName
539540
for entry in archive.Entries do
540-
let destinationPath = Path.GetFullPath(Path.Combine(targetFolder, entry.FullName))
541+
let destinationPath = Path.GetFullPath(Path.Combine(targetFolder, entry.FullName.Trim([| '/'; '\\'|])))
542+
541543
let fi = FileInfo(destinationPath)
544+
let folder = fi.Directory.FullName |> normalizePath
545+
let isSubFolder =
546+
let comparer =
547+
if isLinux then
548+
System.StringComparison.Ordinal
549+
else
550+
System.StringComparison.OrdinalIgnoreCase
551+
552+
folder.StartsWith(target,comparer)
553+
554+
if not isSubFolder then
555+
raise (Exception(sprintf "Error during extraction of %s.%sPackage is corrupted or possible zip leak attac in entry \"%s\"." fileName Environment.NewLine entry.FullName))
556+
542557
if not fi.Directory.Exists then
543558
fi.Directory.Create()
544559
if fi.Exists then

0 commit comments

Comments
 (0)