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 <[email protected]>
Signed-off-by: Jonathan Leitschuh <[email protected]>

Bug-tracker: JLLeitschuh/security-research#10

Co-authored-by: Moderne <[email protected]>
  • Loading branch information
JLLeitschuh and TeamModerne committed Jul 27, 2022
1 parent d9e4b39 commit c5d09fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/test/java/net/smacke/jaydio/align/TestDirectIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Random;

Expand Down Expand Up @@ -63,12 +64,7 @@ public TestDirectIO() {
}

private static File getTempDirectory(String prefix, String suffix) throws IOException {
File temp = File.createTempFile(prefix, suffix);
if(!(temp.delete())) {
throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
} else if (!temp.mkdir()) {
throw new IOException("could not create temporary directory");
}
File temp = Files.createTempDirectory(prefix + suffix).toFile();
return temp;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.channels.NonWritableChannelException;
import java.nio.file.Files;
import java.util.Arrays;

import net.smacke.jaydio.DirectIoLib;
Expand All @@ -43,12 +44,7 @@ public class TestDirectIoByteChannel extends BufferedChannelAbstractTester<Align
private static DirectIoLib lib;

private static File getTempDirectory(String prefix, String suffix) throws IOException {
File temp = File.createTempFile(prefix, suffix);
if(!(temp.delete())) {
throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
} else if (!temp.mkdir()) {
throw new IOException("could not create temporary directory");
}
File temp = Files.createTempDirectory(prefix + suffix).toFile();
return temp;
}

Expand Down

0 comments on commit c5d09fc

Please sign in to comment.