From e20f4fe31ac502e74a43d15c791968a256a2f61d Mon Sep 17 00:00:00 2001 From: "pixeebot[bot]" <23113631+pixeebot@users.noreply.github.com> Date: Thu, 1 Feb 2024 22:41:49 +0000 Subject: [PATCH] Introduced protections against "zip slip" attacks --- .../SPDF/controller/api/pipeline/PipelineProcessor.java | 3 ++- src/main/java/stirling/software/SPDF/utils/FileToPdf.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java b/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java index 5ff6842c..d84ea3c5 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java +++ b/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java @@ -1,5 +1,6 @@ package stirling.software.SPDF.controller.api.pipeline; +import io.github.pixee.security.ZipSecurity; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -356,7 +357,7 @@ public class PipelineProcessor { List unzippedFiles = new ArrayList<>(); try (ByteArrayInputStream bais = new ByteArrayInputStream(data); - ZipInputStream zis = new ZipInputStream(bais)) { + ZipInputStream zis = ZipSecurity.createHardenedInputStream(bais)) { ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { diff --git a/src/main/java/stirling/software/SPDF/utils/FileToPdf.java b/src/main/java/stirling/software/SPDF/utils/FileToPdf.java index bdf3ec61..816cdef6 100644 --- a/src/main/java/stirling/software/SPDF/utils/FileToPdf.java +++ b/src/main/java/stirling/software/SPDF/utils/FileToPdf.java @@ -1,5 +1,6 @@ package stirling.software.SPDF.utils; +import io.github.pixee.security.ZipSecurity; import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -144,7 +145,7 @@ public class FileToPdf { private static Path unzipAndGetMainHtml(byte[] fileBytes) throws IOException { Path tempDirectory = Files.createTempDirectory("unzipped_"); - try (ZipInputStream zipIn = new ZipInputStream(new ByteArrayInputStream(fileBytes))) { + try (ZipInputStream zipIn = ZipSecurity.createHardenedInputStream(new ByteArrayInputStream(fileBytes))) { ZipEntry entry = zipIn.getNextEntry(); while (entry != null) { Path filePath = tempDirectory.resolve(entry.getName());