-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
"Produces" and "consumes" Content-types in schema are not escaped and allow XSS #1866
Comments
Hi Joe, The reason I submitted the original PR is because we are using a profile media-type parameter in our Accept header; in our case it is application/hal+json; charset=utf-8; version=1.0; profile="http://donate-api.justgiving.com/profiles" Before my PR, swagger would create requests with truncated accept headers, at the site of the first quote mark. With respect to the XSS, I am not sure if it should be a concern. I may be wrong, but the only input to these fields comes from the server its self, with no scope for a hostile actor to alter it for subsequent requests. If they wanted to custom-craft a request, there are plenty of tools available for that. Thanks, Jon |
@spadger thanks for the quick response. These XSS vulnerabilities are easily exploitable because swagger-ui's index.html takes a The main reason I am concerned with XSS in this library is because the project advocates hosting swagger-ui directly on your API server; so if you have an authenticated web app hosted on the same domain, swagger-ui becomes part of its attack surface. I'll try out your provided Content-type header and try to figure out what goes wrong, but I suspect your original fix was done in the wrong place. |
Good point; that XSS would be horrendous! I guess it would be possible encode the value in the options and decode when performing the request? I may be able to take a look later, |
@spadger I can't seem to reproduce the original issue; I changed the code to use
The value shows up correctly in the And the Content-type of the request itself seems to be encoded properly:
Am I missing a step? |
Hey Joe, I think I have been a bit dim here - my fix actually changed the {{{ }}} to {{ }} - I added escaping to the solution (but when rendering the value of an option)! As such, with my change - {{}}, the dropdown is rendered as this: application/hal+json; profile="http://donate-api.justgiving.com/profiles"; version=1.0Your PR adds escaping to the rendering of the displayable content of the option, and I can confirm it works with my profile. Jon |
Fix issue #1866, XSS in content types from schema.
I've merged the PR #1867. Thanks guys! |
@spadger ahhh thanks for clearing that up. My eyes glazed right over your actual change - which indeed closed one out of the two XSS vulnerabilities in that template. |
Fix issue swagger-api#1866, XSS in content types from schema.
To reproduce, use the example JSON, but change one of the "consumes" keys like so:
"consumes" =>["application/json","application/xml","\"><script>alert(1)</script>"]
Or:
"produces" =>["application/xml","application/json","\"><script>alert(1)</script>"]
You will see the alert dialog execute.
The text was updated successfully, but these errors were encountered: