From 56af5f821e12e9cb6db12273c5316f1806d3f121 Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Tue, 4 Oct 2022 00:25:23 +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 --- .../universalgcodesender/utils/GcodeStreamTest.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/ugs-core/test/com/willwinder/universalgcodesender/utils/GcodeStreamTest.java b/ugs-core/test/com/willwinder/universalgcodesender/utils/GcodeStreamTest.java index 30d5cac51b..99c3acc8d9 100644 --- a/ugs-core/test/com/willwinder/universalgcodesender/utils/GcodeStreamTest.java +++ b/ugs-core/test/com/willwinder/universalgcodesender/utils/GcodeStreamTest.java @@ -21,6 +21,7 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.universalgcodesender.types.GcodeCommand; import java.io.*; +import java.nio.file.Files; import org.apache.commons.io.FileUtils; import org.junit.AfterClass; @@ -40,17 +41,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); }