From c535f2078f14fd5f7521c5cbf9b72412d07e2524 Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Tue, 4 Oct 2022 00:23:14 +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 --- .../tamingtext/classifier/bayes/ExtractTrainingDataTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/tamingtext/classifier/bayes/ExtractTrainingDataTest.java b/src/test/java/com/tamingtext/classifier/bayes/ExtractTrainingDataTest.java index 5293b10..ee36bcb 100644 --- a/src/test/java/com/tamingtext/classifier/bayes/ExtractTrainingDataTest.java +++ b/src/test/java/com/tamingtext/classifier/bayes/ExtractTrainingDataTest.java @@ -24,6 +24,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.file.Files; import java.util.HashMap; import java.util.Map; @@ -54,9 +55,7 @@ public static void beforeClass() throws Exception { } public static File createTempDirectory() throws IOException { - File file = File.createTempFile("extract-test", "test"); - file.delete(); - file.mkdirs(); + File file = Files.createTempDirectory("extract-test" + "test").toFile(); if (!file.isDirectory()) { throw new IOException("Could not create temporary directory: " + file); }