{"id":"CVE-2021-21430","aliases":["CVE-2021-21430","GHSA-cqxr-xf2w-943w"],"related":[],"kind":"vulnerability","state":"published","title":"Creation of Temporary File in Directory with Insecure Permissions in auto-generated Java, Scala code","summary":"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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.","source":"cvelist"},{"lang":"en","text":"### Impact\n\n**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!\n\nOn 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.\n\nThis 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.\n\nAuto-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.\n\nAffected generators: \n - Java\n   - `okhttp-gson` (default library)\n     https://github.com/OpenAPITools/openapi-generator/blob/d85f61ff0cfd6b8cd7063a63f302998a51466269/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache#L1085-L1088\n   - `jersey2`\n     https://github.com/OpenAPITools/openapi-generator/blob/d85f61ff0cfd6b8cd7063a63f302998a51466269/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache#L1035-L1038\n   - `resteasy`\n     https://github.com/OpenAPITools/openapi-generator/blob/d85f61ff0cfd6b8cd7063a63f302998a51466269/modules/openapi-generator/src/main/resources/Java/libraries/resteasy/ApiClient.mustache#L604-L607\n   - `retrofit2`\n      https://github.com/OpenAPITools/openapi-generator/blob/d85f61ff0cfd6b8cd7063a63f302998a51466269/modules/openapi-generator/src/main/resources/Java/libraries/retrofit2/play26/ApiClient.mustache#L202-L208\n - Scala\n   - `scala-finch`\n      https://github.com/OpenAPITools/openapi-generator/blob/764a3b044c19fadf4a0789473cde96a65b77868a/modules/openapi-generator/src/main/resources/scala-finch/api.mustache#L83-L88\n   - `scala-akka`\n      https://github.com/OpenAPITools/openapi-generator/blob/150e24dc553a8ea5230ffb938ed3e6020e972faa/modules/openapi-generator/src/main/resources/scala-akka-http-server/multipartDirectives.mustache#L71-L73\n\n### Patches\n\nThe 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.\n\nThis 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.\nhttps://github.com/swagger-api/swagger-codegen/security/advisories/GHSA-hpv8-9rq5-hq7w\n\n### For more information\nIf you have any questions or comments about this advisory:\n* Open an issue in [OpenAPI Generator Github repo](https://github.com/openAPITools/openapi-generator/)\n* Email us at [security@openapitools.org](mailto:security@openapitools.org)","format":"markdown","source":"ghsa"},{"lang":"es","text":"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","source":"nvd"}],"published":"2021-05-10T19:25:12.000Z","modified":"2026-07-08T06:28:34.537Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N","score":6.2,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N","score":6.2,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N","score":6.2,"rating":"MEDIUM"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N","score":5.5,"rating":"MEDIUM"},{"scorer":"NVD","scheme":"CVSS:2.0","vector":"AV:L/AC:L/Au:N/C:P/I:N/A:N","score":2.1,"rating":"LOW"}],"cwes":["CWE-269","CWE-377","CWE-378","CWE-379","CWE-668"],"affected":[{"ranges":[{"version":"< 5.1.0","status":"affected"}],"vendor":"OpenAPITools","product":"openapi-generator","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"5.1.0"}],"ecosystem":"Maven","package":"org.openapitools:openapi-generator","purl":"pkg:maven/org.openapitools/openapi-generator","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"5.1.1"}],"vendor":"openapi-generator","product":"openapi_generator","cpe":"cpe:2.3:a:openapi-generator:openapi_generator:*:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://github.com/OpenAPITools/openapi-generator/security/advisories/GHSA-cqxr-xf2w-943w","tags":["exploit","third-party-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/OpenAPITools/openapi-generator/pull/8791","tags":["patch","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/OpenAPITools/openapi-generator/pull/8787","tags":["patch","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2021-21430","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/OpenAPITools/openapi-generator/pull/9348","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/OpenAPITools/openapi-generator","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2021-21430","url":"https://www.cve.org/CVERecord?id=CVE-2021-21430","licence":"CVE Terms of Use","modified":"2024-08-03T18:09:16.157Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-cqxr-xf2w-943w","url":"https://github.com/advisories/GHSA-cqxr-xf2w-943w","licence":"CC-BY-4.0","modified":"2026-07-08T06:28:34.537Z"},{"source":"nvd","name":"NVD","id":"CVE-2021-21430","url":"https://nvd.nist.gov/vuln/detail/CVE-2021-21430","licence":"Public domain","modified":"2026-06-17T03:35:33.643Z"}],"updatedAt":"2026-11-25T22:58:01.262Z","epss":{"score":0.00404,"percentile":0.36763,"date":"2026-12-01T12:00:22.000Z"}}