Skip to content

Commit 7e9fc30

Browse files
vuln-fix: Temporary Directory Hijacking or Information Disclosure (#389)
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]>
1 parent 776d17a commit 7e9fc30

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

hamcrest/src/test/java/org/hamcrest/io/FileMatchersTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.File;
77
import java.io.IOException;
8+
import java.nio.file.Files;
89

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

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

1718
@Override
1819
protected void setUp() throws IOException {
19-
directory = File.createTempFile("myDir", "");
20-
assertTrue("deleting " + directory, directory.delete());
21-
assertTrue("mkdir " + directory, directory.mkdirs());
20+
directory = Files.createTempDirectory("myDir").toFile();
21+
assertTrue("deleting " + directory, true);
22+
assertTrue("mkdir " + directory, true);
2223

2324
file = new File(directory, "myFile");
2425
file.createNewFile();

0 commit comments

Comments
 (0)