Skip to content

Commit

Permalink
vuln-fix: Temporary Directory Hijacking or Information Disclosure (#389)
Browse files Browse the repository at this point in the history
Simplify the creation of temp dir in FileMatchersTest

This was originally identified as a security vulnerability (see details below), but inspection of the code showed that the vulnerability was not actually present in the code, as the original code does check the return code of `directory.delete()` and `directory.mkdirs()`. The PR was accepted because the change actually is an improvement to the code anyway.

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 <[email protected]>
Bug-tracker: JLLeitschuh/security-research#10
Co-authored-by: Moderne <[email protected]>
  • Loading branch information
JLLeitschuh and TeamModerne authored Jul 20, 2024
1 parent 776d17a commit 7e9fc30
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions hamcrest/src/test/java/org/hamcrest/io/FileMatchersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import static org.hamcrest.core.IsEqual.equalTo;

Expand All @@ -16,9 +17,9 @@ public class FileMatchersTest extends AbstractMatcherTest {

@Override
protected void setUp() throws IOException {
directory = File.createTempFile("myDir", "");
assertTrue("deleting " + directory, directory.delete());
assertTrue("mkdir " + directory, directory.mkdirs());
directory = Files.createTempDirectory("myDir").toFile();
assertTrue("deleting " + directory, true);
assertTrue("mkdir " + directory, true);

file = new File(directory, "myFile");
file.createNewFile();
Expand Down

0 comments on commit 7e9fc30

Please sign in to comment.