swagger-api / swagger-api/swagger-codegen
[SWIFT3] URL parameters are not escaped
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
swagger-codegen does not properly escape parametrized parts of a URL.
For example:
var path = "/recipient/{recipient}"
path = path.replacingOccurrences(of: "{recipient}", with: "\(recipient)", options: .literal, range: nil)
The "recipient" variable should be URLEscaped, but it isn't. Thus, if recipient contains spaces or illegal characters, the request fails. Depending on the source of the parameters, this could also lead to vulnerable code.
Swagger-codegen version
git commit id 18c57a65ed5def618be6495e86fd2d0c73f89882
Swagger declaration file content or url
n/a
Command line used for generation
not relevnt
Steps to reproduce
Use a swagger API that has parameters in the URL, for example: /article/{articleName}, then use "Hello World ../" as articleName
Related issues/PRs
n/a
Suggest a fix/enhancement
Properly url escape the passed parameters:
let param1 = param.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Swift 3 template or generated client code that performs the shown replacement for parametrized URL paths. Reproduce the issue with an articleName such as "Hello World ../" and compare the generated request path with the expected escaped value. Done means URL parameters are escaped before insertion without breaking valid paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100