Skip to content

Commit

Permalink
Prevent Zip Slip when using ArchiveFileStreamContext to decompress
Browse files Browse the repository at this point in the history
  • Loading branch information
robmen committed Sep 17, 2019
1 parent 88d93f6 commit dadd0a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions history/zipslip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* RobMen: WIXBUG:6075 - Fix "Zip Slip" vulnerability in DTF.
12 changes: 12 additions & 0 deletions src/DTF/Libraries/Compression/ArchiveFileStreamContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ private string TranslateFilePath(string path)

if (filePath != null)
{
this.ValidateArchivePath(filePath);

if (this.directory != null)
{
filePath = Path.Combine(this.directory, filePath);
Expand All @@ -647,6 +649,16 @@ private string TranslateFilePath(string path)
return filePath;
}

private void ValidateArchivePath(string filePath)
{
string basePath = Path.GetFullPath(String.IsNullOrEmpty(this.directory) ? Environment.CurrentDirectory : this.directory);
string path = Path.GetFullPath(Path.Combine(basePath, filePath));
if (!path.StartsWith(basePath, StringComparison.InvariantCultureIgnoreCase))
{
throw new InvalidDataException("Archive cannot contain files with absolute or traversal paths.");
}
}

#endregion
}
}

0 comments on commit dadd0a6

Please sign in to comment.