From aa29adca6374df18a483b1b6c2ed3c8d58ca522a Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Fri, 18 Nov 2022 22:40:41 +0000 Subject: [PATCH 1/2] 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 --- .../org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java b/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java index 872bf80..1663ad7 100644 --- a/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java +++ b/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.Reader; import java.io.Writer; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -553,7 +554,7 @@ private File generatePomFile() try { - File tempFile = File.createTempFile( "mvndeploy", ".pom" ); + File tempFile = Files.createTempFile( "mvndeploy", ".pom" ).toFile(); tempFile.deleteOnExit(); try ( Writer fw = WriterFactory.newXmlWriter( tempFile ) ) From 311fc4705d8e95c9a95ff836f07e2187bdac5257 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Tue, 15 Aug 2023 10:46:07 +0200 Subject: [PATCH 2/2] Fix typo --- .../org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java b/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java index f728299..e2a151c 100644 --- a/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java +++ b/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java @@ -490,7 +490,7 @@ private File generatePomFile() throws MojoExecutionException { Model model = generateModel(); try { - File tempFile = Files.createTempFile("mvndeploy", ".pom".toFile(); + File tempFile = Files.createTempFile("mvndeploy", ".pom").toFile(); tempFile.deleteOnExit(); try (Writer fw = WriterFactory.newXmlWriter(tempFile)) {