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

CRLF injection #1

Closed
chadwhitacre opened this issue Jun 16, 2015 · 19 comments
Closed

CRLF injection #1

chadwhitacre opened this issue Jun 16, 2015 · 19 comments
Labels

Comments

@chadwhitacre
Copy link
Contributor

https://gratipay.freshdesk.com/helpdesk/tickets/2305

== CRLF Injection (Chrome, Internet Explorer) ==
http://gratipay.com/%0dSet-Cookie:csrf_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;

Response:
Location: https://gratipay.com/\r
Set-Cookie:csrf_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;\r\n

@chadwhitacre
Copy link
Contributor Author

Really it's header injection:

$ curl -I http://localhost:8537/%0dFoo:%20Bar
HTTP/1.1 302 Found
Server: gunicorn/18.0
Date: Mon, 29 Jun 2015 13:15:41 GMT
Connection: close
Transfer-Encoding: chunked
X-Gratipay-Version: 1860
X-Frame-Options: SAMEORIGIN
Foo: Bar/ /
Set-Cookie: csrf_token=[]; expires=Mon, 06 Jul 2015 13:15:41 GMT; Path=/
Cache-Control: no-cache

$

@chadwhitacre
Copy link
Contributor Author

I believe the bug is in how we handle redirects.

@chadwhitacre
Copy link
Contributor Author

I put a set_trace in aspen.http.Request.redirect and I don't hit it! Following up on gratipay/gratipay.com#2138 (comment):

Yeah, looks like we have some code that manually performs redirection.

@chadwhitacre
Copy link
Contributor Author

I'm finding four places outside of Request.redirect where we construct redirect responses:

@chadwhitacre
Copy link
Contributor Author

Really it's header injection:

Sorry, I misread "CRLF injection" in the title as "CSRF injection."

@chadwhitacre
Copy link
Contributor Author

For the test case above, we're hitting the second dispatcher redirect (to trailing slash).

@chadwhitacre
Copy link
Contributor Author

Okay! What's the best fix?

@chadwhitacre
Copy link
Contributor Author

Seems like a safe, low-level place to fix this bug would be in Response.__init__ or possibly even in Mapping.{__set_item__,add}. Note that the latter is shared with the body parsing machinery, where we don't want to clobber \r.

@chadwhitacre
Copy link
Contributor Author

Or is now the time to migrate Aspen to Werkzeug? Cf. AspenWeb/pando.py#357.

@chadwhitacre
Copy link
Contributor Author

Here's Werkzeug's protection against this.

@chadwhitacre
Copy link
Contributor Author

Hah! We already have LF injection protection. We just need to add CR injection protection. ;-)

The other limitation with our current implementation is that adding a second value for the same header doesn't go through BaseHeaders.__setitem__.

@chadwhitacre
Copy link
Contributor Author

Ping @pjz.

@chadwhitacre
Copy link
Contributor Author

@pjz I just added you to the Gratipay security team so you can help me land the fix for this. You available? :)

@chadwhitacre
Copy link
Contributor Author

Fixed in Aspen 0.39.

@techtonik
Copy link

Niiice. Did you find any real threats for CRLF injection in GP?

@chadwhitacre
Copy link
Contributor Author

Fix deployed in gratipay/gratipay.com#3588, but gratipay/gratipay.com#3594 is causing a 500. Still considering this fixed tho:

$ curl -I http://gratipay.com/%0dSet-Cookie:csrf_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Server: gunicorn/18.0
Date: Thu, 02 Jul 2015 21:46:59 GMT
Transfer-Encoding: chunked
Via: 1.1 vegur

$

@chadwhitacre
Copy link
Contributor Author

@chadwhitacre
Copy link
Contributor Author

To: researcher

The CRLF Injection and CSRF Protection Bypass bugs should be fixed now. Please confirm.

I've added you to our legacy Halls of Fame for Aspen (for the CRLF injection) and Gratipay (for the CSRF protection bypass):

http://aspen.io/security.txt
https://gratipay.com/about/security/hall-of-fame

We've now migrated our security program to HackerOne. If you would like acknowledgement on HackerOne feel free to re-file the bugs there and I will resolve them.

Thanks for the reports! :-)

@chadwhitacre
Copy link
Contributor Author

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

No branches or pull requests

2 participants