Skip to content

Commit

Permalink
fix: Fix potential security issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Romuald Rousseau committed Sep 22, 2024
1 parent b44f148 commit 8b973af
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

public class Disk
{
private static final List<String> DANGEROUS_PATH = List.of("..", ".");

public static void copyDir(Path src, Path dest) throws IOException {
Files.walk(src).forEach(source -> copyFile(source, dest.resolve(src.relativize(source))));
}
Expand Down Expand Up @@ -49,12 +46,11 @@ public static void unzipDir(final Path zipFile, final Path folder) throws IOExce
try (final var zis = new ZipInputStream(new FileInputStream(zipFile.toFile()))) {
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
if (DANGEROUS_PATH.contains(ze.getName())) {
continue;
final var newFile = folder.resolve(ze.getName()).normalize();
if (!newFile.startsWith(folder)) {
throw new IOException("Bad zip entry: " + ze.getName());
}

final var newFile = folder.resolve(ze.getName());

// Ensure parent directory exists
newFile.getParent().toFile().mkdirs();

Expand Down

0 comments on commit 8b973af

Please sign in to comment.