Skip to content

Commit c33595f

Browse files
wing328padznich
andcommitted
Update python sdk to strip any directory traversal in filename (OpenAPITools#22965)
* update python sdk Strip any directory traversal * rebased * update samples, docs * fallback case --------- Co-authored-by: Pavel Slabko <slabkopg@gmail.com> # Conflicts: # modules/openapi-generator/src/main/resources/python/api_client.mustache # samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py # samples/client/echo_api/python/openapi_client/api_client.py # samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py # samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py # samples/openapi3/client/petstore/python-lazyImports/petstore_api/api_client.py # samples/openapi3/client/petstore/python/petstore_api/api_client.py
1 parent b97766d commit c33595f

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

modules/openapi-generator/src/main/resources/python/api_client.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,8 @@ class ApiClient:
725725
)
726726
assert m is not None, "Unexpected 'content-disposition' header value"
727727
filename = os.path.basename(m.group(1)) # Strip any directory traversal
728+
if filename in ("", ".", ".."): # fall back to tmp filename
729+
filename = os.path.basename(path)
728730
path = os.path.join(os.path.dirname(path), filename)
729731

730732
with open(path, "wb") as f:

0 commit comments

Comments
 (0)