<img src=“https://badge.fury.io/rb/ssl_routes.png” alt=“Gem Version” /> <img src=“https://secure.travis-ci.org/cedric/ssl_routes.png?branch=master” alt=“Build Status” /> <img src=“https://codeclimate.com/github/cedric/ssl_routes.png” /> <img src=“https://gemnasium.com/cedric/ssl_routes.svg” alt=“Dependency Status” />
NOTE: This gem is no longer being maintained.
This gem was created to enforce SSL in a Rails app based on the defined routes. Unlike ssl_requirement, controllers will use the routes to determine enforcement. In order to prevent redirects between protocols where possible, the routes will also be used to generate URLs – such as those created by url_for and Paperclip. This means that there will be little need to redirect the user, which is a security issue when sensitive data has already been sent. Finally, in response to session hijacking tools such as Firesheep, you can place all logged-in traffic under SSL. Please feel free to contribute improvements and bug fixes.
-
Rails 2.3 support was removed in version 0.2.0.
-
The secure_session setting now defaults to true.
Add the following to your Gemfile:
gem 'ssl_routes'
Place enforce_protocols with the configuration block in ApplicationController and define the configuration options.
This is the parameter in your routes file that pertains to the protocol. The default is to use the standard :protocol, but you can use a custom one if you want.
This is to defend against session hijacking tools such as Firesheep. When a user is logged-in (requires current_user) all traffic will go under SSL. In order for this to work, routes must exist for both protocols. This means using a custom parameter (such as :ssl => true/false) that can drive your protocol preference but leave both routes intact.
This is to enable or disable SSL. Useful for turning it on or off based on the environment, a session variable or a user setting.
class ApplicationController < ActionController::Base enforce_protocols do |config| config.parameter = :ssl config.secure_session = true config.enable_ssl = true end end
ActionController::Routing::Routes.draw do |map| map.signup '/signup', :controller => 'users', :action => 'new', :ssl => true end
Any helper that uses url_for will use the current protocol to determine if a full URL is needed:
signup_path => https://hostname/signup
If the current protocol is correct, then nothing changes:
signup_path => /signup
If using Rails 3.1 or the Rack::SSL gem, use the :exclude option to allow both http and https traffic:
config.middleware.use Rack::SSL, :exclude => proc { |env| env['HTTPS'] != 'on' }
(The MIT License)
Copyright © 2011-2013 Cedric Howe
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.