From ff1e8a535d4f3778a4abce98deeefb55a803ee16 Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Fri, 18 Nov 2022 22:41:37 +0000 Subject: [PATCH] vuln-fix: Temporary File Information Disclosure 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 Signed-off-by: Jonathan Leitschuh Bug-tracker: https://github.com/JLLeitschuh/security-research/issues/18 Co-authored-by: Moderne --- .../maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java index b3e8cc40..2659d04c 100644 --- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java +++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.Reader; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -855,7 +856,7 @@ else if ( "plain".equals( outputFileFormat ) ) { // Write a plain output file to the standard output file, // and write an XML output file to the temp directory that can be used to count violations - outputXmlFile = File.createTempFile( "checkstyle-result", ".xml" ); + outputXmlFile = Files.createTempFile( "checkstyle-result", ".xml" ).toFile(); outputXmlFile.deleteOnExit(); OutputStream xmlOut = getOutputStream( outputXmlFile ); CompositeAuditListener compoundListener = new CompositeAuditListener();