Skip to content

Commit

Permalink
fix(store): Zip Slip issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Pengzna committed Apr 18, 2024
1 parent 8df9e32 commit 6e629b1
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.zip.CheckedInputStream;
import java.util.zip.CheckedOutputStream;
Expand Down Expand Up @@ -78,7 +79,13 @@ public static void decompress(final String sourceFile, final String outputDir,
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
final String fileName = entry.getName();
final File entryFile = new File(Paths.get(outputDir, fileName).toString());
final Path entryPath = Paths.get(outputDir).resolve(fileName).normalize();
if (!entryPath.startsWith(Paths.get(outputDir).normalize())) {
// The file path is not in the expected directory. There may be a Zip Slip
// vulnerability. Ignore it or handle it accordingly.
continue;
}
final File entryFile = entryPath.toFile();
FileUtils.forceMkdir(entryFile.getParentFile());
try (final FileOutputStream fos = new FileOutputStream(entryFile);
final BufferedOutputStream bos = new BufferedOutputStream(fos)) {
Expand Down

0 comments on commit 6e629b1

Please sign in to comment.