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 be0a837 commit 17680b7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ public static abstract class LocalFactoryImpl implements JenkinsControllerFactor
protected LocalController(Injector i) {
super(i);
try {
jenkinsHome = File.createTempFile("jenkins", "home", new File(WORKSPACE));
jenkinsHome.delete();
jenkinsHome.mkdirs();
jenkinsHome = Files.createTempDirectory(new File(WORKSPACE).toPath(), "jenkins" + "home").toFile();
} catch (IOException e) {
throw new RuntimeException("Failed to create a temp file",e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ public GitRepo addSubmodule(String submoduleName) {
}

private File createTempDir(String name) throws IOException {
File tmp = File.createTempFile("jenkins", name);
tmp.delete();
tmp.mkdir();
File tmp = Files.createTempDirectory("jenkins" + name).toFile();
return tmp;
}

Expand Down
5 changes: 2 additions & 3 deletions src/test/java/plugins/GerritTriggerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,8 @@ private void checkApprovalValueFromJSON(String json, String labelName, int value
}

private File createGitCommit(String jobName) throws IOException, InterruptedException {
File dir = File.createTempFile("jenkins","git");
dir.delete();//result !needed
assertTrue(dir.mkdir());
File dir = Files.createTempDirectory("jenkins" + "git").toFile();//result !needed
assertTrue(true);

ProcessBuilder pb = new ProcessBuilder("git", "clone", gtGerrituser
+ "@" + gtHostname + ":"
Expand Down

0 comments on commit 17680b7

Please sign in to comment.