Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T00004 - Extracting archives should not lead to zip slip vulnerabilities #43570

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/Installer/core-sdk-tasks/ExtractArchiveToDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override bool ValidateParameters()
Log.LogMessage($"Creating Directory {DestinationDirectory}");
Directory.CreateDirectory(DestinationDirectory);
}

return retVal;
}

Expand Down Expand Up @@ -88,13 +88,22 @@ public override bool Execute()
{
if (ShouldExtractItem(entry.FullName))
{
if (!Directory.Exists(Path.Combine(DestinationDirectory, Path.GetDirectoryName(entry.FullName))))
var fullDestinationPath = Path.GetFullPath(Path.Combine(DestinationDirectory, entry.FullName));
if (!fullDestinationPath.StartsWith(Path.GetFullPath(DestinationDirectory), StringComparison.Ordinal))
guilhermelinosp marked this conversation as resolved.
Show resolved Hide resolved
{
Log.LogMessage($"Warning: Skipping invalid entry {entry.FullName} (potential zip slip attack)");
continue;
}

var directoryPath = Path.GetDirectoryName(fullDestinationPath);
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(Path.Combine(DestinationDirectory, Path.GetDirectoryName(entry.FullName)));
Directory.CreateDirectory(directoryPath);
}

Log.LogMessage(Path.GetDirectoryName(entry.FullName));
entry.ExtractToFile(Path.Combine(loc, entry.FullName));
// Log the directory path and extract the file
Log.LogMessage(directoryPath);
entry.ExtractToFile(fullDestinationPath, overwrite: true);
}
}
}
Expand Down
Loading