Devise Security Extension
An enterprise security extension for Devise, trying to meet industrial standard security demands for web applications.
It is composed of 7 additional Devise modules:
:password_expirable
- passwords will expire after a configured time (and will need an update):secure_validatable
- better way to validate a model (email, stronger password validation). Don't use with Devise :validatable
module!:password_archivable
- save used passwords in an old_passwords
table for history checks (don't be able to use a formerly used password):session_limitable
- ensures, that there is only one session usable per account at once:expirable
- expires a user account after x days of inactivity (default 90 days):security_questionable
- as accessible substitution for captchas (security question with captcha fallback):paranoid_verification
- admin can generate verification code that user needs to fill in otherwise he wont be able to use the application.
Configuration and database schema for each module below.
Additional features
- captcha support for
sign_up
, sign_in
, recover
and unlock
(to make automated mass creation and brute forcing of accounts harder)
Getting started
Devise Security Extension works with Devise on Rails 3.2 onwards. You can add it to your Gemfile after you successfully set up Devise (see Devise documentation) with:
gem 'devise_security_extension'
Run the bundle command to install it.
After you installed Devise Security Extension you need to run the generator:
rails generate devise_security_extension:install
The generator adds optional configurations to config/initializers/devise.rb
. Enable
the modules you wish to use in the initializer you are ready to add Devise Security Extension modules on top of Devise modules to any of your Devise models:
devise :password_expirable, :secure_validatable, :password_archivable, :session_limitable, :expirable
for :secure_validatable
you need to add
gem 'rails_email_validator'
Configuration
Devise.setup do |config|
end
Captcha-Support
The captcha support depends on EasyCaptcha. See further documention there.
Installation
- Add EasyCaptcha to your
Gemfile
with
gem 'easy_captcha'
- Run the initializer
rails generate easy_captcha:install
- Enable captcha - see "Configuration" of Devise Security Extension above.
- Add the captcha in the generated devise views for each controller you have activated
<p><%= captcha_tag %></p>
<p><%= text_field_tag :captcha %></p>
Schema
Password expirable
create_table :the_resources do |t|
t.datetime :password_changed_at
end
add_index :the_resources, :password_changed_at
Password archivable
create_table :old_passwords do |t|
t.string :encrypted_password, :null => false
t.string :password_archivable_type, :null => false
t.integer :password_archivable_id, :null => false
t.datetime :created_at
end
add_index :old_passwords, [:password_archivable_type, :password_archivable_id], :name => :index_password_archivable
Session limitable
create_table :the_resources do |t|
t.string :unique_session_id, :limit => 20
end
Expirable
create_table :the_resources do |t|
t.datetime :last_activity_at
t.datetime :expired_at
end
add_index :the_resources, :last_activity_at
add_index :the_resources, :expired_at
Paranoid verifiable
create_table :the_resources do |t|
t.string :paranoid_verification_code
t.integer :paranoid_verification_attempt, default: 0
t.datetime :paranoid_verified_at
end
add_index :the_resources, :paranoid_verification_code
add_index :the_resources, :paranoid_verified_at
Documentation for Paranoid Verifiable module
Security questionable
class SecurityQuestion < ActiveRecord::Base
validates :locale, presence: true
validates :name, presence: true, uniqueness: true
end
create_table :security_questions do |t|
t.string :locale, :null => false
t.string :name, :null => false
end
SecurityQuestion.create! locale: :de, name: 'Wie lautet der Geburstname Ihrer Mutter?'
SecurityQuestion.create! locale: :de, name: 'Wo sind sie geboren?'
SecurityQuestion.create! locale: :de, name: 'Wie lautet der Name Ihres ersten Haustieres?'
SecurityQuestion.create! locale: :de, name: 'Was ist Ihr Lieblingsfilm?'
SecurityQuestion.create! locale: :de, name: 'Was ist Ihr Lieblingsbuch?'
SecurityQuestion.create! locale: :de, name: 'Was ist Ihr Lieblingstier?'
SecurityQuestion.create! locale: :de, name: 'Was ist Ihr Lieblings-Reiseland?'
add_column :the_resources, :security_question_id, :integer
add_column :the_resources, :security_question_answer, :string
or
create_table :the_resources do |t|
t.integer :security_question_id
t.string :security_question_answer
end
Requirements
Todo
- see the github issues (feature requests)
History
- 0.1 expire passwords
- 0.2 strong password validation
- 0.3 password archivable with validation
- 0.4 captcha support for sign_up, sign_in, recover and unlock
- 0.5 session_limitable module
- 0.6 expirable module
- 0.7 security questionable module for recover and unlock
- 0.8 Support for Rails 4 (+ variety of patches)
Maintainers
Contributing to devise_security_extension
- Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
- Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
- Fork the project
- Start a feature/bugfix branch
- Commit and push until you are happy with your contribution
- Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
- Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
Copyright
Copyright (c) 2011-2015 Marco Scholl. See LICENSE.txt for further details.