Skip to content

Commit

Permalink
vuln-fix: Temporary Directory Hijacking or Information Disclosure
Browse files Browse the repository at this point in the history
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 <Jonathan.Leitschuh@gmail.com>
Signed-off-by: Jonathan Leitschuh <Jonathan.Leitschuh@gmail.com>

Bug-tracker: JLLeitschuh/security-research#10

Co-authored-by: Moderne <team@moderne.io>
  • Loading branch information
JLLeitschuh and TeamModerne committed Jul 27, 2022
1 parent a2100e3 commit 77f0db5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/test/java/jnr/posix/windows/WindowsFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.text.NumberFormat;
import jnr.posix.DummyPOSIXHandler;
import jnr.posix.FileStat;
Expand All @@ -15,8 +16,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import static org.junit.Assert.assertTrue;

public class WindowsFileTest {
private static POSIX posix;

Expand Down Expand Up @@ -52,9 +53,7 @@ public void cleanup(File node) {
// FIXME: This is a broken method since it does not delete any of the generated dirs.
private static final String DIR_NAME = "0123456789";
private Pair makeLongPath() throws IOException {
File tmp = File.createTempFile("temp", Long.toHexString(System.nanoTime()));

if (!(tmp.delete() && tmp.mkdir())) throw new IOException("Could not make a long path");
File tmp = Files.createTempDirectory("temp" + Long.toHexString(System.nanoTime())).toFile();

StringBuilder buf = new StringBuilder(DIR_NAME);
for (int i = 0; i < 30; i++) {
Expand Down

0 comments on commit 77f0db5

Please sign in to comment.