Avoid zipSlip vulnerability.

This commit is contained in:
tastybento 2021-09-12 21:53:26 -07:00
parent 5b838d0668
commit bb7f124066

View File

@ -192,6 +192,9 @@ public class BlueprintClipboardManager {
if (!entry.isDirectory()) {
unzipFiles(zipInputStream, filePath);
} else {
if (!filePath.startsWith(blueprintFolder.getAbsolutePath())) {
throw new IOException("Entry is outside of the target directory");
}
Files.createDirectories(filePath);
}
@ -202,6 +205,9 @@ public class BlueprintClipboardManager {
}
private void unzipFiles(final ZipInputStream zipInputStream, final Path unzipFilePath) throws IOException {
if (!unzipFilePath.toAbsolutePath().toString().startsWith(blueprintFolder.getAbsolutePath())) {
throw new IOException("Entry is outside of the target directory");
}
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(unzipFilePath.toAbsolutePath().toString()))) {
byte[] bytesIn = new byte[1024];
int read;