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
JLLeitschuh and TeamModerne committed Nov 18, 2022
1 parent 2ac0443 commit 161e5c2
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.security.MessageDigest;
Expand Down Expand Up @@ -132,7 +133,7 @@ private static void calculateFromEntityWriter(Request.EntityWriter entityWriter,
File tempFile = null;
OutputStream os = null;
try {
tempFile = File.createTempFile("crxPartBase", ".dat");
tempFile = Files.createTempFile("crxPartBase", ".dat").toFile();
os = new BufferedOutputStream(new FileOutputStream(tempFile));

entityWriter.writeEntity(os);
Expand All @@ -154,7 +155,7 @@ private static void calculateFromPartBase(PartBase part, RequestBuilderBase<?> r
File tempFile = null;
OutputStream os = null;
try {
tempFile = File.createTempFile("crxPartBase", ".dat");
tempFile = Files.createTempFile("crxPartBase", ".dat").toFile();
os = new BufferedOutputStream(new FileOutputStream(tempFile));

part.send(os);
Expand Down

0 comments on commit 161e5c2

Please sign in to comment.