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 Oct 4, 2022
1 parent b174ef5 commit 0250033
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -99,10 +100,7 @@ public void testCreateArchiveWithDetectedModes()
File tmpDir = null;
try
{
tmpDir = File.createTempFile( "tbz2-with-chmod.", ".dir" );
tmpDir.delete();

tmpDir.mkdirs();
tmpDir = Files.createTempDirectory("tbz2-with-chmod." + ".dir").toFile();

for ( String executablePath : executablePaths )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -125,9 +126,7 @@ public void testUseAttributesFromTarArchiveInputInTarArchiverOutput()
// Cut from here, and feed it into a new tar archiver...then unarchive THAT.
TarUnArchiver tarUnArchiver = (TarUnArchiver) lookup( UnArchiver.ROLE, "tar" );

File tempTarDir = File.createTempFile( "tar-test.", ".dir" );
tempTarDir.delete();
tempTarDir.mkdirs();
File tempTarDir = Files.createTempDirectory("tar-test." + ".dir").toFile();

toDelete.add( tempTarDir );

Expand Down Expand Up @@ -189,9 +188,7 @@ public void testUseDetectedFileAttributes()

TarUnArchiver tarUnArchiver = (TarUnArchiver) lookup( UnArchiver.ROLE, "tar" );

File tempTarDir = File.createTempFile( "tar-test.", ".dir" );
tempTarDir.delete();
tempTarDir.mkdirs();
File tempTarDir = Files.createTempDirectory("tar-test." + ".dir").toFile();

toDelete.add( tempTarDir );

Expand Down Expand Up @@ -253,9 +250,7 @@ public void testOverrideDetectedFileAttributes()

TarUnArchiver tarUnArchiver = (TarUnArchiver) lookup( UnArchiver.ROLE, "tar" );

File tempTarDir = File.createTempFile( "tar-test.", ".dir" );
tempTarDir.delete();
tempTarDir.mkdirs();
File tempTarDir = Files.createTempDirectory("tar-test." + ".dir").toFile();

toDelete.add( tempTarDir );

Expand Down Expand Up @@ -319,9 +314,7 @@ public void testOverrideDetectedFileAttributesUsingFileMode()

TarUnArchiver tarUnArchiver = (TarUnArchiver) lookup( UnArchiver.ROLE, "tar" );

File tempTarDir = File.createTempFile( "tar-test.", ".dir" );
tempTarDir.delete();
tempTarDir.mkdirs();
File tempTarDir = Files.createTempDirectory("tar-test." + ".dir").toFile();

toDelete.add( tempTarDir );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Date;
import java.util.Enumeration;
Expand Down Expand Up @@ -160,10 +161,7 @@ public void testCreateArchiveWithDetectedModes()
File tmpDir = null;
try
{
tmpDir = File.createTempFile( "zip-with-chmod.", ".dir" );
tmpDir.delete();

tmpDir.mkdirs();
tmpDir = Files.createTempDirectory("zip-with-chmod." + ".dir").toFile();

for ( String executablePath : executablePaths )
{
Expand Down

0 comments on commit 0250033

Please sign in to comment.