What does force_ssl do in Rails?

It doesn’t just force your browser to redirect HTTP to HTTPS. It also sets your cookies to be marked “secure”, and it enables HSTS, each of which are very good protections against SSL stripping.

Even though HTTPS protects your app at “https://example.com/yourapp” against MITM attacks, if someone gets between your client and your server they can rather easily get you to visit “http://example.com/yourapp“. With neither of the above protections, your browser will happily send the session cookie to the person doing the MITM.

Leave a Comment