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 d9af702 commit bf9fb4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ void setup() {
@DisplayName("should be able to create based on a worktree")
@Test
void testCreateWithWorkTree() throws Exception {
File workTree = File.createTempFile("workTree", null);
if (workTree.delete() && workTree.mkdir()) {
workTree.deleteOnExit();
}
File workTree = Files.createTempDirectory("workTree").toFile();
workTree.deleteOnExit();

File gitDir = new File(workTree, DOT_GIT);
if (gitDir.mkdir()) {
Expand Down Expand Up @@ -125,10 +123,8 @@ void testCreateWithWorkTreeAndGitDir() throws Exception {
@DisplayName("should be able to create based on a subdirectory of a worktree")
@Test
void testCreateWithWorkTreeChild() throws Exception {
File workTree = File.createTempFile("workTree", null);
if (workTree.delete() && workTree.mkdir()) {
workTree.deleteOnExit();
}
File workTree = Files.createTempDirectory("workTree").toFile();
workTree.deleteOnExit();

File workTreeChild = new File(workTree, "child");
if (workTreeChild.mkdir()) {
Expand Down Expand Up @@ -157,20 +153,16 @@ void testCreateWithWorkTreeChild() throws Exception {
@DisplayName("should be able to create based on a linked worktree")
@Test
void testCreateWithLinkedWorktree() throws Exception {
File realGitDir = File.createTempFile(DOT_GIT, null);
if (realGitDir.delete() && realGitDir.mkdir()) {
realGitDir.deleteOnExit();
}
File realGitDir = Files.createTempDirectory(DOT_GIT).toFile();
realGitDir.deleteOnExit();

File gitDir = new File(realGitDir, DOT_GIT + "/worktrees/test");
if (gitDir.mkdir()) {
gitDir.deleteOnExit();
}

File workTree = File.createTempFile("workTree", null);
if (workTree.delete() && workTree.mkdir()) {
workTree.deleteOnExit();
}
File workTree = Files.createTempDirectory("workTree").toFile();
workTree.deleteOnExit();

File originalGitDir = new File(workTree, DOT_GIT);
Files.createFile(originalGitDir.toPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.codehaus.plexus.util.FileUtils;

import java.io.File;
import java.nio.file.Files;
import java.util.Properties;

import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -179,9 +180,7 @@ void testInitErrorSkipNoGit() throws Exception {
@DisplayName("should ignore errors when skipNoGit is set")
@Test
void testInitRepository() throws Exception {
File baseDir = File.createTempFile("mavanagaiata-tests-baseDir", null);
baseDir.delete();
baseDir.mkdirs();
File baseDir = Files.createTempDirectory("mavanagaiata-tests-baseDir").toFile();
FileUtils.forceDeleteOnExit(baseDir);

File gitDir = File.createTempFile("mavanagaiata-tests-gitDir", null);
Expand Down

0 comments on commit bf9fb4d

Please sign in to comment.