Question: I am hosting an ASP.NET MVC 4 site on AppHarbor (which uses Amazon EC2), and I'm using CloudFlare for Flexible SSL. I'm having a problem with redirect loops (310) when trying to use RequireHttps. The problem is that, like EC2, CloudFlare terminates the SSL before forwarding the request onto the server. However, whereas Amazon sets the X-Forwarded-Proto header so that you can handle the request with a custom filter, CloudFlare does not appear to. Or if they do, I don't know how they are doing it, since I can't intercept traffic at that level. I've tried the solutions for Amazon EC2, but they don't seem to help with CloudFlare.

Has anyone experienced this issue, or know enough about CloudFlare to help?

Answer: 
The `X-Forwarded-Proto` header is intentionally overridden by AppHarbor's load balancers to the actual scheme of the request.

Note that while CloudFlare's flexible SSL option may add slightly more security, there is still unencrypted traffic travelling over the public internet from CloudFlare to AppHarbor. This arguably defies the purpose of SSL for anything else than appearances and reducing the number of attack vectors (like packet sniffing on the user's local network) - i.e. it may look "professional" to your users, but it actually is still insecure.

That's less than ideal particularly since AppHarbor supports both installing your own certificates and includes piggyback SSL out of the box. CloudFlare also recommends using "Full SSL" for scenarios where the origin servers/service support SSL. So you have a couple of options:

* Continue to use the insecure "Flexible SSL" option, but instead of inspecting the `X-Forwarded-Proto` header in your custom `RequireHttps` filter, you should inspect the `scheme` attribute of the `CF-Visitor` header. There are more details in [this discussion](https://support.cloudflare.com/entries/22088068-How-do-I-redirect-HTTPS-traffic-with-Flexible-SSL-and-Apache-).
* Use "Full SSL" and point CloudFlare to your `*.apphb.com` hostname. This way you can use the complimentary piggyback SSL that is enabled by default with your AppHarbor app. You'll have to override the `Host` header on CloudFlare to make this work and [here's a blog post on how to do that](http://blog.cloudflare.com/ssl-on-custom-domains-for-appengine-and-other). This will of course make requests to your app appear like they were made to your `*.apphb.com` domain - so if for instance you automatically redirect requests to a "canonical" URL or generate absolute URLs you'll likely have to take this into consideration.
* Upload your certificate and add a custom hostname to AppHarbor. Then turn on "Full SSL" on CloudFlare. This way the host header will remain the same and your application will continue to work without any modifications. You can read more about the SSL options offered by AppHarbor in [this knowledge base article](http://support.appharbor.com/kb/tips-and-tricks/ssl-and-certificates).
Or you could just get a free one year SSL cert signed by StartCom and upload that to AppHarbor.

Then you can call it a day and pat yourself on the back! That is until future you one year from now has to purchase a cert =).