Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CVE-2016-5641 #3201

Merged
merged 1 commit into from
Jun 27, 2016
Merged

CVE-2016-5641 #3201

merged 1 commit into from
Jun 27, 2016

Conversation

sdavis-r7
Copy link
Contributor

please reference https://community.rapid7.com/community/infosec/blog/2016/06/23/r7-2016-06-remote-code-execution-via-swagger-parameter-injection-cve-2016-5641

    * ping @ the authors of the individual language modules
    * java @cbornet , @xhh ,@epaul
    * ruby @wing328 , @zlx 
    * javascript @xhh 
    * php @arnested 

@sdavis-r7
Copy link
Contributor Author

ping @cbornet , @xhh, @ePaul (java), @wing328 (ruby), @xhh (javascript), @arnested (php)

@todb-r7
Copy link

todb-r7 commented Jun 23, 2016

This is a proposed security fix, by the way.

We attempted to notify SmartBear and apiteam@swagger.io, as did CERT (after we notified CERT), but to no avail.

Please consider a security@swagger.io alias to make reporting vulnerabilities a smoother process for next time.

@sdavis-r7
Copy link
Contributor Author

sdavis-r7 commented Jun 23, 2016

please note. this build failure looks to be because of the python swagger petstore client... python is not something this PR has touched

 [INFO] Python Swagger Petstore Client .................... FAILURE [1:01.897s]

jdk1.7 passsed, where as jdk1.8 did not (on a python client?) please advise.

Local jdk1.8 with mvn test ends in success.

@wing328
Copy link
Contributor

wing328 commented Jun 23, 2016

@sdavis-r7 I've restarted the job and now the CI tests passed.

Thanks for the PR. We'll review and let you know if we've any questions.

@ePaul
Copy link
Contributor

ePaul commented Jun 23, 2016

@sdavis-r7 thanks for this finding. I guess I never had the idea to run code generated from an untrusted API definition. (Though I'm mainly using OpenAPI/Swagger in company-internal APIs, which are extensively reviewed.)

From the document:

Until code generators are patched by their maintainers, users are advised to carefully inspect Swagger documents for language-specific escape sequences.

Either this, or review the generated code (if you know the language). Or use just trusted API definitions.

*/
{{#allParams}} // * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not knowing PHP that well, this looks like not the correct syntax for a documentation comment. (Might be acceptable for fixing the vulnerability, but should be changed later so something better, e.g. using a similar approach as for the other languages.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ePaul Thank you! The intent for to force it as single line, though I am very open to suggestions on modification here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdavis-r7 I'll probably keep * and sanitize the tag to remove line break instead so as to conform to the PHP coding style.

@sdavis-r7
Copy link
Contributor Author

@ePaul Trusted API can mean many things if you consider the channel between. I think that need be considered for what threat value it may have, and to your point about ensuring one can trust the provider & channel.

ePaul added a commit to ePaul/swagger-codegen that referenced this pull request Jun 23, 2016
@ePaul
Copy link
Contributor

ePaul commented Jun 23, 2016

I did generate the petstore samples once with current master and once after merging this PR's branch. The changes can be seen in 2dad256 – mainly comment changes for PHP, and an added # in the Ruby docs.

@ePaul
Copy link
Contributor

ePaul commented Jun 23, 2016

I reproduced the Java example, but I got problems with reproducing the Node JS one. @sdavis-r7 Did you use nodejs-server, or some other one?

@sdavis-r7
Copy link
Contributor Author

sdavis-r7 commented Jun 23, 2016

@ePaul nodejs-client/javascript

ePaul added a commit to ePaul/swagger-codegen that referenced this pull request Jun 23, 2016
@ePaul
Copy link
Contributor

ePaul commented Jun 23, 2016

Verified and approved for language java and variants thereof (i.e. everything based on the changed AbstractJavaCodegen). 001c2c3 demonstrates the problem, 77fd629 the solution. (Maybe we should put that into some test case.)

👍

The example exploit just seems to apply to client side code (e.g. default Java client), but I guess similar vulnerabilities are there for some server implementations.

I didn't find any language named nodejs-client in current master – maybe @sdavis-r7 used an older version where this did exist, or some other product based on this which adds this?

I can't really judge on the fix for other languages.

@sdavis-r7
Copy link
Contributor Author

sdavis-r7 commented Jun 23, 2016

@ePaul this client: http://generator.swagger.io/api/gen/clients/javascript

To be clear, The nodejs/javascript was client side (codegen). I feel the server side (codgen) should definitely be scrutinized.

I will give the nodejs-server a once or twice over now.

@sdavis-r7
Copy link
Contributor Author

sdavis-r7 commented Jun 23, 2016

@ePaul I was at first feeling I was on to the unsanitzed 'example' section of service.mustache

  {{#examples}}examples['{{contentType}}'] = {{{example}}};

though it appears to ' & " are santized in this.

disclaimer: This is my attempt, and I may be missing something, but I don't see any current issues with nodejs-server .

@fehguy
Copy link
Contributor

fehguy commented Jun 24, 2016

Folks, thanks for the discussion and discovery of the vulnerability. I believe proper escaping of all triple-mustache variables should be done in the language-specific template pre-processor, and that all uses of triple mustaches should be run through a specific escape logic, since escaping techniques vary between languages. This should have been done a while ago just to clean up the logic, but the vulnerability gives us a good reason to do so.

Suggest we make the escape code abstract in the interface so it must be chosen in a language-specific implementation. In addition, an inventory of the triple mustaches should be done.

@wing328 wing328 added this to the v2.2.0 milestone Jun 24, 2016
@ePaul
Copy link
Contributor

ePaul commented Jun 24, 2016

@fehguy I'm not sure if concentrating on the triple mustaches is enough. While the double-mustaches are HTML-escaped, I think for some languages dangerous code can still get through.

@fehguy
Copy link
Contributor

fehguy commented Jun 24, 2016

@ePaul can you give an example?

@sdavis-r7
Copy link
Contributor Author

@fehguy @ePaul {{}} is not enough for languages where things can be done 'beneath the radar' of html escaping. For example:

(via model.mustache in the php resources)

/* 
{{description}} 
*/

lets the following through

/* 
*/ echo system(chr(0x63).chr(0x61).chr(0x74).chr(0x20).chr(0x2f).chr(0x65).chr(0x74).chr(0x63).chr(0x2f).chr(0x70).chr(0x61).chr(0x73).chr(0x73).chr(0x77).chr(0x64) ); /* 
*/

Perhaps there need be deeper sanitization effforts before the template variables at a core location? A tricky task, but the usually recommended approach in AppSec/OWASP land.

@fehguy
Copy link
Contributor

fehguy commented Jun 24, 2016

@sdavis-r7 got it, thanks. I'll think through some solutions for this and post back, probably in separate tickets. I think the fixes proposed in this PR address some of the issues but a more comprehensive fix is needed.

@sdavis-r7
Copy link
Contributor Author

@fehguy excellent. Not sure it 'fits', though the OWASP ESAPI is potentially useful here for a type of central component model. ⛄

@wing328 wing328 merged commit 8066639 into swagger-api:master Jun 27, 2016
@rpgreen
Copy link

rpgreen commented Jun 27, 2016

When can we expect this fix to be officially released?

@wing328
Copy link
Contributor

wing328 commented Jun 28, 2016

@rpgreen we still need to go through each language one by one.

I just filed #3224 to provide better handle of potential code injection for PHP API client.

For your environment, is that allowed to use the latest master in production?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants