Impact
This vulnerability impacts generated code. If this code was generated as a one-off occasion, not as a part of an automated CI/CD process, this code will remain vulnerable until fixed manually!
On Unix-Like systems, the system temporary directory is shared between all local users. When files/directories are created, the default umask
settings for the process are respected. As a result, by default, most processes/apis will create files/directories with the permissions -rw-r--r--
and drwxr-xr-x
respectively, unless an API that explicitly sets safe file permissions is used.
This vulnerability exists due to the use of the JDK method File.createTempFile
. This method creates an insecure temporary files that can leave application and system data vulnerable to exposure.
Auto-generated code (Java, Scala) that deals with uploading or downloading binary data through API endpoints will create insecure temporary files during the process. For example, if the API endpoint returns a PDF file, the auto-generated clients will first download the PDF into a insecure temporary file that can be read by anyone on the system.
Affected generators:
- Java
okhttp-gson
(default library)
|
if (tempFolderPath == null) |
|
return File.createTempFile(prefix, suffix); |
|
else |
|
return File.createTempFile(prefix, suffix, new File(tempFolderPath)); |
jersey2
|
if (tempFolderPath == null) |
|
return File.createTempFile(prefix, suffix); |
|
else |
|
return File.createTempFile(prefix, suffix, new File(tempFolderPath)); |
resteasy
|
if (tempFolderPath == null) |
|
return File.createTempFile(prefix, suffix); |
|
else |
|
return File.createTempFile(prefix, suffix, new File(tempFolderPath)); |
retrofit2
|
@Override |
|
public File convert(ResponseBody value) throws IOException { |
|
|
|
File file = File.createTempFile("retrofit-file", ".tmp"); |
|
Files.write(Paths.get(file.getPath()), value.bytes()); |
|
return file; |
|
} |
- Scala
scala-finch
|
private def bytesToFile(input: Array[Byte]): java.io.File = { |
|
val file = File.createTempFile("tmp{{classname}}", null) |
|
val output = new FileOutputStream(file) |
|
output.write(input) |
|
file |
|
} |
scala-akka
|
val tempFileFromFileInfo: FileInfo => File = { |
|
file: FileInfo => File.createTempFile(file.fileName, ".tmp") |
|
} |
Patches
The issue has been patched by changing the generated code to use the JDK method Files.createTempFile
and released in the v5.1.0 stable version.
References
#8787
#8791
#9348
This vulnerability has the same root cause as CVE-2021-21364 from the swagger-api/swagger-codegen
project as this project and that one both share the same original source tree.
GHSA-hpv8-9rq5-hq7w
For more information
If you have any questions or comments about this advisory:
Impact
This vulnerability impacts generated code. If this code was generated as a one-off occasion, not as a part of an automated CI/CD process, this code will remain vulnerable until fixed manually!
On Unix-Like systems, the system temporary directory is shared between all local users. When files/directories are created, the default
umask
settings for the process are respected. As a result, by default, most processes/apis will create files/directories with the permissions-rw-r--r--
anddrwxr-xr-x
respectively, unless an API that explicitly sets safe file permissions is used.This vulnerability exists due to the use of the JDK method
File.createTempFile
. This method creates an insecure temporary files that can leave application and system data vulnerable to exposure.Auto-generated code (Java, Scala) that deals with uploading or downloading binary data through API endpoints will create insecure temporary files during the process. For example, if the API endpoint returns a PDF file, the auto-generated clients will first download the PDF into a insecure temporary file that can be read by anyone on the system.
Affected generators:
okhttp-gson
(default library)openapi-generator/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache
Lines 1085 to 1088 in d85f61f
jersey2
openapi-generator/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache
Lines 1035 to 1038 in d85f61f
resteasy
openapi-generator/modules/openapi-generator/src/main/resources/Java/libraries/resteasy/ApiClient.mustache
Lines 604 to 607 in d85f61f
retrofit2
openapi-generator/modules/openapi-generator/src/main/resources/Java/libraries/retrofit2/play26/ApiClient.mustache
Lines 202 to 208 in d85f61f
scala-finch
openapi-generator/modules/openapi-generator/src/main/resources/scala-finch/api.mustache
Lines 83 to 88 in 764a3b0
scala-akka
openapi-generator/modules/openapi-generator/src/main/resources/scala-akka-http-server/multipartDirectives.mustache
Lines 71 to 73 in 150e24d
Patches
The issue has been patched by changing the generated code to use the JDK method
Files.createTempFile
and released in the v5.1.0 stable version.References
#8787
#8791
#9348
This vulnerability has the same root cause as CVE-2021-21364 from the
swagger-api/swagger-codegen
project as this project and that one both share the same original source tree.GHSA-hpv8-9rq5-hq7w
For more information
If you have any questions or comments about this advisory: