The ExtractToFile()
method takes in a parameter that specifies the destination to which the archive is to be extracted. However, it is possible that this parameter may be unsanitized, especially if it is manually constructed. In such cases, you may end up extracting the archive to a destination outside your control, especially if one or more parameters are obtained via user input. It is therefore recommended that you ensure that this destination is precisely what you need, meaning, the archive is being extracted to the destination that you intend to.
var destination = directory + folder;
archive.ExtractToFile(destination);
var destination = directory + folder;
if (destination.StartsWith(safeDestination))
{
archive.ExtractToFile(destination);
}