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 0619c20 commit 0d3b204
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
13 changes: 2 additions & 11 deletions src/main/java/doc/UnZip.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import javax.swing.*;
import java.io.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
Expand All @@ -23,17 +24,7 @@ public static File createTempDirectory()
throws IOException {
final File temp;

temp = File.createTempFile("temp", Long.toString(System.nanoTime()));

if(!(temp.delete()))
{
throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
}

if(!(temp.mkdir()))
{
throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
}
temp = Files.createTempDirectory("temp" + Long.toString(System.nanoTime())).toFile();

return (temp);
}
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/doc_gui/NotebookPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -878,17 +879,7 @@ public void save() {
public static File createTempDirectory() throws IOException{
final File temp;

temp = File.createTempFile("temp", Long.toString(System.nanoTime()));

if(!(temp.delete()))
{
throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
}

if(!(temp.mkdir()))
{
throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
}
temp = Files.createTempDirectory("temp" + Long.toString(System.nanoTime())).toFile();

return (temp);
}
Expand Down

0 comments on commit 0d3b204

Please sign in to comment.