From b621a797e7bb4dd2ea831e050653f47d272b3db0 Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Tue, 4 Oct 2022 00:21:29 +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 --- .../disconf/client/test/support/utils/DirUtils.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/disconf-client/src/test/java/com/baidu/disconf/client/test/support/utils/DirUtils.java b/disconf-client/src/test/java/com/baidu/disconf/client/test/support/utils/DirUtils.java index 93b0b4c94..2d5224090 100644 --- a/disconf-client/src/test/java/com/baidu/disconf/client/test/support/utils/DirUtils.java +++ b/disconf-client/src/test/java/com/baidu/disconf/client/test/support/utils/DirUtils.java @@ -2,6 +2,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; /** * @author liaoqiqi @@ -13,15 +14,7 @@ public static File createTempDirectory() throws IOException { final File temp; - temp = File.createTempFile("temp", Long.toString(System.nanoTime())); - - if (!(temp.delete())) { - throw new IOException("Could not delete temp file: " + temp.getAbsolutePath()); - } - - if (!(temp.mkdir())) { - throw new IOException("Could not create temp directory: " + temp.getAbsolutePath()); - } + temp = Files.createTempDirectory("temp" + Long.toString(System.nanoTime())).toFile(); return (temp); }