I need to create a temporary file and store some data into it. I have written the following code to do so:
import org.apache.commons.lang.RandomStringUtils;
import java.security.SecureRandom;
[...]
String random = RandomStringUtils.random(10, 0, 0, true, true, null, new SecureRandom());
File tempFile = File.createTempFile("PREFIX-" + random, ".pdf");
[...]
It does work perfectly, but when I submit this code to Veracode, I get an “Insecure Temporary File (CWE ID 377)” error.
I thought that using SecureRandom
will make the temporary file name impossible to predict by attackers.
What is the right way to generate a temporary file without making Veracode unhappy?
Files.createTempFile
? – WeddleFiles.createTempFile()
clear the issue with Veracode? – Bilestone