Skip to content

Commit

Permalink
vuln-fix: Temporary File Information Disclosure
Browse files Browse the repository at this point in the history
This fixes temporary file information disclosure vulnerability due to the use
of the vulnerable `File.createTempFile()` method. The vulnerability is fixed by
using the `Files.createTempFile()` method which sets the correct posix permissions.

Weakness: CWE-377: Insecure Temporary File
Severity: Medium
CVSSS: 5.5
Detection: CodeQL & OpenRewrite (https://public.moderne.io/recipes/org.openrewrite.java.security.SecureTempFileCreation)

Reported-by: Jonathan Leitschuh <[email protected]>
Signed-off-by: Jonathan Leitschuh <[email protected]>

Bug-tracker: JLLeitschuh/security-research#18


Co-authored-by: Moderne <[email protected]>
  • Loading branch information
2 people authored and DImuthuUpe committed Nov 27, 2022
1 parent 92ed154 commit 9d32413
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.slf4j.LoggerFactory;

import java.io.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -239,7 +240,7 @@ private SSHClient getSSHClient(SCPStorage scpStorage, SCPSecret scpSecret) throw

sshClient.addHostKeyVerifier((h, p, key) -> true);

File privateKeyFile = File.createTempFile("id_rsa", "");
File privateKeyFile = Files.createTempFile("id_rsa", "").toFile();
BufferedWriter writer = new BufferedWriter(new FileWriter(privateKeyFile));
writer.write(scpSecret.getPrivateKey());
writer.close();
Expand Down

0 comments on commit 9d32413

Please sign in to comment.