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 ddfe78d commit b6f5633
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import net.sourceforge.jenesis4java.AbstractMethod;
import net.sourceforge.jenesis4java.Access;
Expand Down Expand Up @@ -96,9 +97,7 @@ public class Test {
@org.junit.Test
public void test1() throws IOException {
this.vm = VirtualMachine.getVirtualMachine();
File tempDirectory = File.createTempFile("jenesisTmp", "tmp");
tempDirectory.delete();
tempDirectory.mkdirs();
File tempDirectory = Files.createTempDirectory("jenesisTmp" + "tmp").toFile();
// make a new compilation unit
CompilationUnit unit = this.vm.newCompilationUnit(tempDirectory.getCanonicalPath());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -127,9 +128,7 @@ private String importResolvedClassName(String className) {

@Test
public void test2() throws IOException {
File tempDirectory = File.createTempFile("jenesisTmp", "tmp");
tempDirectory.delete();
tempDirectory.mkdirs();
File tempDirectory = Files.createTempDirectory("jenesisTmp" + "tmp").toFile();
// make a new compilation unit
CompilationUnit unit = this.vm.newCompilationUnit(tempDirectory.getCanonicalPath());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

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

import net.sourceforge.jenesis4java.Access;
import net.sourceforge.jenesis4java.Annotation;
Expand All @@ -59,9 +60,7 @@ public class TestAnnotation {
public void test3() throws IOException {

VirtualMachine vm = VirtualMachine.getVirtualMachine();
File tempDirectory = File.createTempFile("jenesisTmp", "tmp");
tempDirectory.delete();
tempDirectory.mkdirs();
File tempDirectory = Files.createTempDirectory("jenesisTmp" + "tmp").toFile();
// make a new compilation unit
CompilationUnit unit = vm.newCompilationUnit(tempDirectory.getCanonicalPath());
PackageClass cls = unit.newClass("HelloWorld");
Expand Down

0 comments on commit b6f5633

Please sign in to comment.