From c5d09fcbafb4a5bb4060184f1008e07f1642d79a Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Wed, 27 Jul 2022 16:36:22 +0000 Subject: [PATCH] vuln-fix: Temporary Directory Hijacking or Information Disclosure This fixes either Temporary Directory Hijacking, or Temporary Directory Local Information Disclosure. Weakness: CWE-379: Creation of Temporary File in Directory with Insecure Permissions Severity: High CVSSS: 7.3 Detection: CodeQL & OpenRewrite (https://public.moderne.io/recipes/org.openrewrite.java.security.UseFilesCreateTempDirectory) Reported-by: Jonathan Leitschuh Signed-off-by: Jonathan Leitschuh Bug-tracker: https://github.com/JLLeitschuh/security-research/issues/10 Co-authored-by: Moderne --- src/test/java/net/smacke/jaydio/align/TestDirectIO.java | 8 ++------ .../smacke/jaydio/channel/TestDirectIoByteChannel.java | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/test/java/net/smacke/jaydio/align/TestDirectIO.java b/src/test/java/net/smacke/jaydio/align/TestDirectIO.java index 2a12df9..4f93434 100644 --- a/src/test/java/net/smacke/jaydio/align/TestDirectIO.java +++ b/src/test/java/net/smacke/jaydio/align/TestDirectIO.java @@ -18,6 +18,7 @@ import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; +import java.nio.file.Files; import java.util.Arrays; import java.util.Random; @@ -63,12 +64,7 @@ public TestDirectIO() { } private static File getTempDirectory(String prefix, String suffix) throws IOException { - File temp = File.createTempFile(prefix, suffix); - if(!(temp.delete())) { - throw new IOException("Could not delete temp file: " + temp.getAbsolutePath()); - } else if (!temp.mkdir()) { - throw new IOException("could not create temporary directory"); - } + File temp = Files.createTempDirectory(prefix + suffix).toFile(); return temp; } diff --git a/src/test/java/net/smacke/jaydio/channel/TestDirectIoByteChannel.java b/src/test/java/net/smacke/jaydio/channel/TestDirectIoByteChannel.java index 2fbe5eb..6a97df3 100644 --- a/src/test/java/net/smacke/jaydio/channel/TestDirectIoByteChannel.java +++ b/src/test/java/net/smacke/jaydio/channel/TestDirectIoByteChannel.java @@ -18,6 +18,7 @@ import java.io.File; import java.io.IOException; import java.nio.channels.NonWritableChannelException; +import java.nio.file.Files; import java.util.Arrays; import net.smacke.jaydio.DirectIoLib; @@ -43,12 +44,7 @@ public class TestDirectIoByteChannel extends BufferedChannelAbstractTester