From 761f80b111fa450cc460906acb4cb3b067785ed6 Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Sat, 19 Nov 2022 03:03:50 +0000 Subject: [PATCH] vuln-fix: Temporary File Information Disclosure This fixes temporary file information disclosure vulnerability due to the use of the vulnerable `File.createTempFile()` method. The vulnerability is fixed by using the `Files.createTempFile()` method which sets the correct posix permissions. Weakness: CWE-377: Insecure Temporary File Severity: Medium CVSSS: 5.5 Detection: CodeQL & OpenRewrite (https://public.moderne.io/recipes/org.openrewrite.java.security.SecureTempFileCreation) Reported-by: Jonathan Leitschuh Signed-off-by: Jonathan Leitschuh Bug-tracker: https://github.com/JLLeitschuh/security-research/issues/18 Co-authored-by: Moderne --- .../servlets/post/impl/helper/SlingFileUploadHandler.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java b/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java index d1ee4ff..87e4420 100644 --- a/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java +++ b/src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java @@ -24,6 +24,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.SequenceInputStream; +import java.nio.file.Files; import java.util.Arrays; import java.util.Calendar; import java.util.Collections; @@ -365,7 +366,7 @@ private File mergeChunks(final Resource parentResource, SequenceInputStream mergeStrm = null; File file = null; try { - file = File.createTempFile("tmp-", "-mergechunk"); + file = Files.createTempFile("tmp-", "-mergechunk").toFile(); out = new FileOutputStream(file); String startPattern = SlingPostConstants.CHUNK_NODE_NAME + "_" + "0_"; Iterator itr = new FilteringResourceIterator(parentResource.listChildren(), startPattern); @@ -595,4 +596,4 @@ private Resource createWithChanges(final Resource parent, final String name, return result; } -} \ No newline at end of file +}