From f346a740d57da50af7f6fbbc5e8cf6c94045241c Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Wed, 27 Jul 2022 16:36: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 --- .../jenkinsci/plugins/mber/FileUploadCallableTest.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/jenkinsci/plugins/mber/FileUploadCallableTest.java b/src/test/java/org/jenkinsci/plugins/mber/FileUploadCallableTest.java index 9452609..7b02b19 100644 --- a/src/test/java/org/jenkinsci/plugins/mber/FileUploadCallableTest.java +++ b/src/test/java/org/jenkinsci/plugins/mber/FileUploadCallableTest.java @@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.nio.file.Files; import net.sf.json.JSONObject; import org.junit.Assert; import org.junit.Test; @@ -68,13 +69,7 @@ private void assertNotEmpty(final String message, final String value) private File makeTempDir() throws IOException { - final File 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()); - } + final File temp = Files.createTempDirectory("temp" + Long.toString(System.nanoTime())).toFile(); Assert.assertTrue("Directory isn't a folder: " + temp.getAbsolutePath(), temp.isDirectory()); return temp; }