From d02268ff4704ada1e5fa669ecfaa7b4b0b529d4a Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Sat, 19 Nov 2022 21:18:59 +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 Co-authored-by: Michael Tughan --- .../scriptler/restapi/ScriptlerRestApiTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/jenkinsci/plugins/scriptler/restapi/ScriptlerRestApiTest.java b/src/test/java/org/jenkinsci/plugins/scriptler/restapi/ScriptlerRestApiTest.java index 919ce741..b08bf02d 100644 --- a/src/test/java/org/jenkinsci/plugins/scriptler/restapi/ScriptlerRestApiTest.java +++ b/src/test/java/org/jenkinsci/plugins/scriptler/restapi/ScriptlerRestApiTest.java @@ -12,11 +12,12 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import org.apache.commons.fileupload.FileItem; -import org.apache.commons.io.FileUtils; import org.jenkinsci.plugins.scriptler.ScriptlerManagementHelper; import org.jenkinsci.plugins.scriptler.ScriptlerManagement; import org.jenkinsci.plugins.scriptler.config.Parameter; @@ -51,9 +52,9 @@ public void setup() throws Exception { } private void saveFile(ScriptlerManagementHelper helper, String scriptId, String scriptContent) throws Exception { - File f = File.createTempFile(scriptId, "-temp"); - FileUtils.writeStringToFile(f, scriptContent); - FileItem fi = new FileItemImpl(f); + Path f = Files.createTempFile("script", "-temp"); + Files.writeString(f, scriptContent); + FileItem fi = new FileItemImpl(f.toFile()); helper.saveScript(fi, true, scriptId); } @@ -126,4 +127,4 @@ public void testUnknownScript() throws Exception { JenkinsRule.WebClient webClient = j.createWebClient(); webClient.goTo("scriptler/runScript?id=unknown.groovy"); } -} \ No newline at end of file +}