CVE-2021-21430
JSON

6.2medium

Creation of Temporary File in Directory with Insecure Permissions in auto-generated Java, Scala code

Severity
6.2medium CVSS:3.1 by GitHub_M
Exploit likelihood
0.40% (higher than 36% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-cqxr-xf2w-943w

Description

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec. Using `File.createTempFile` in JDK will result in creating and using insecure temporary files that can leave application and system data vulnerable to attacks. Auto-generated code (Java, Scala) that deals with uploading or downloading binary data through API endpoints will create insecure temporary files during the process. Affected generators: `java` (jersey2, okhttp-gson (default library)), `scala-finch`. The issue has been patched with `Files.createTempFile` and released in the v5.1.0 stable version.

Affected

Product or packageVersionsReported by
OpenAPITools openapi-generator< 5.1.0CVE List
org.openapitools:openapi-generator (Maven)before 5.1.0GitHub Advisory Database
openapi-generator openapi_generatorbefore 5.1.1NVD

All scores

GitHub_M6.2medium CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
GitHub6.2medium CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
NVD5.5medium CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N
NVD2.1low CVSS:2.0AV:L/AC:L/Au:N/C:P/I:N/A:N

Classification

What each source says

CVE List

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec. Using `File.createTempFile` in JDK will result in creating and using insecure temporary files that can leave application and system data vulnerable to attacks. Auto-generated code (Java, Scala) that deals with uploading or downloading binary data through API endpoints will create insecure temporary files during the process. Affected generators: `java` (jersey2, okhttp-gson (default library)), `scala-finch`. The issue has been patched with `Files.createTempFile` and released in the v5.1.0 stable version.

GitHub Advisory Database
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:

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.

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. https://github.com/swagger-api/swagger-codegen/security/advisories/GHSA-hpv8-9rq5-hq7w

For more information

If you have any questions or comments about this advisory:

NVD (es)

OpenAPI Generator permite la generación de bibliotecas de cliente API (generación de SDK), stubs de servidor, documentación y configuración de forma automática dada una especificación de OpenAPI.&#xa0;El uso de "File.createTempFile" en JDK dará como resultado la creación y el uso de archivos temporales no seguros que pueden dejar la aplicación y los datos del sistema vulnerables a los ataques.&#xa0;El código generado automáticamente (Java, Scala) que se ocupa de cargar o descargar datos binarios por medio de los endpoints de la API creará archivos temporales no seguros durante el proceso.&#xa0;Generadores afectados: "java" (jersey2, okhttp-gson (biblioteca predeterminada)),"scala-finch".&#xa0;El problema se corrigió con "Files.createTempFile" y se lanzó en la versión estable v5.1.0

References

Sources

SourceRecordLicence
CVE ListCVE-2021-21430 changed 2024-08-03CVE Terms of Use
GitHub Advisory DatabaseGHSA-cqxr-xf2w-943w changed 2026-07-08CC-BY-4.0
NVDCVE-2021-21430 changed 2026-06-17Public domain