From bbaa5b687fc6fc8264e06cdf4072deb16f19e37d Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Tue, 4 Oct 2022 00:25:15 +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 --- .../org/apache/axiom/attachments/PartOnFileTest.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java b/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java index a0780052..f319f6ea 100644 --- a/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java +++ b/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java @@ -26,6 +26,7 @@ import javax.activation.DataSource; import java.io.File; import java.io.InputStream; +import java.nio.file.Files; /** Test the PartOnFile class */ @@ -114,15 +115,7 @@ public void testGetAllheaders() throws Exception { } private void createTemporaryDirectory() throws Exception { - temp = File.createTempFile("partOnFileTest", ".tmp"); - - if (!temp.delete()) { - fail("Cannot delete from temporary directory. File: " + temp.toURL()); - } - - if (!temp.mkdir()) { - fail("Cannot create a temporary location for part files"); - } + temp = Files.createTempDirectory("partOnFileTest" + ".tmp").toFile(); } private void deleteTemporaryDirectory() throws Exception {