From be64b6f1b3d4d7b6cfdce12c0f3953be6a1ff195 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 22 Feb 2021 16:32:33 +0800 Subject: [PATCH 1/2] use Files.createTempFile to address security concerns --- .../org/openapitools/codegen/online/service/Generator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java index 1ea9af624df9..51912448dc80 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java @@ -35,6 +35,7 @@ import org.springframework.web.server.ResponseStatusException; import java.io.File; +import java.nio.file.Files; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -181,7 +182,7 @@ private static String generate(String language, GeneratorInput opts, Type type) private static File getTmpFolder() { try { - File outputFolder = File.createTempFile("codegen-", "-tmp"); + File outputFolder = Files.createTempFile("codegen-", "-tmp").toFile(); outputFolder.delete(); outputFolder.mkdir(); outputFolder.deleteOnExit(); From 0c38e6dfcee4d3dacb29755e7c796942aefbfb2c Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 23 Feb 2021 11:34:20 +0800 Subject: [PATCH 2/2] Update modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java Co-authored-by: Jonathan Leitschuh --- .../org/openapitools/codegen/online/service/Generator.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java index 51912448dc80..878a33f09bb4 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java @@ -182,9 +182,7 @@ private static String generate(String language, GeneratorInput opts, Type type) private static File getTmpFolder() { try { - File outputFolder = Files.createTempFile("codegen-", "-tmp").toFile(); - outputFolder.delete(); - outputFolder.mkdir(); + File outputFolder = Files.createTempDirectory("codegen-tmp").toFile(); outputFolder.deleteOnExit(); return outputFolder; } catch (Exception e) {