Skip to content

Commit 9180593

Browse files
authored
[maven plugin] fix security issues (#8795)
* use Files.createTempFile in maven plugin to avoid security issues * error check when creating a folder
1 parent c31e6e7 commit 9180593

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

  • modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin

modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,10 @@ public void execute() throws MojoExecutionException {
758758

759759
if (storedInputSpecHashFile.getParent() != null && !new File(storedInputSpecHashFile.getParent()).exists()) {
760760
File parent = new File(storedInputSpecHashFile.getParent());
761-
parent.mkdirs();
761+
if (!parent.mkdirs()) {
762+
throw new RuntimeException("Failed to create the folder " + parent.getAbsolutePath() +
763+
" to store the checksum of the input spec.");
764+
}
762765
}
763766
Files.asCharSink(storedInputSpecHashFile, StandardCharsets.UTF_8).write(inputSpecHash);
764767

@@ -790,7 +793,7 @@ private String calculateInputSpecHash(File inputSpecFile) throws IOException {
790793
File inputSpecTempFile = inputSpecFile;
791794

792795
if (inputSpecRemoteUrl != null) {
793-
inputSpecTempFile = File.createTempFile("openapi-spec", ".tmp");
796+
inputSpecTempFile = java.nio.file.Files.createTempFile("openapi-spec", ".tmp").toFile();
794797

795798
URLConnection conn = inputSpecRemoteUrl.openConnection();
796799
if (isNotEmpty(auth)) {

0 commit comments

Comments
 (0)