
Security News
Rspack Introduces Rslint, a TypeScript-First Linter Written in Go
Rspack launches Rslint, a fast TypeScript-first linter built on typescript-go, joining in on the trend of toolchains creating their own linters.
This gem aims to improve the security of your rails application. It allows you to add a TTL (Time To Live) to the session cookie and allows you to bind the session to an IP address.
When the TTL expires or the IP address changes, the users session gets reset. This should help to make session-fixation-attacks harder to execute.
Consider the following attack vector: The web application under attack is a rails application. The application writes the user id in the session after a successful login. The attacker has obtained a valid session cookie from an authenticated user. By default the cookie is valid indefinitely. If the application tries to "reset the session" it simply issues a new session cookie to the attackers browser. If the attacker just ignores the new session cookie and continues to use the old session cookie the application has no way of knowing that.
By adding a TTL the attack window gets smaller. An stolen has to be used within a given time slot. A reauthentication is enforced after a given time has passed. By adding IP address binding the attacker has to use the same ip address as the victim the session was stolen from.
Rails 5.2 and 6.x and 7.0 are currently supported.
Add this line to your application's Gemfile:
gem 'frikandel'
And then execute:
$ bundle
Or install it yourself as:
$ gem install frikandel
You can use session TTL or the combination of TTL and IP address binding. Please be advised that the sole use of IP address binding doesn't protect from session-fixation-attacks.
To activate Frikandel's session-fixation-protection for your application, you only need to include the proper module(s) in your ApplicationController
:
class ApplicationController < ActionController::Base
include Frikandel::LimitSessionLifetime
include Frikandel::BindSessionToIpAddress
# ...
end
To configure frikandel's TTL-values, you can add an initializer in config/initializers
namend frikandel.rb
and insert the following lines:
Frikandel::Configuration.max_ttl = 2.days
Frikandel::Configuration.ttl = 4.hours
The value at Frikandel::Configuration.max_ttl
is the absolute value (in seconds) that a cookie is valid. In this example, all cookies will be invalidated after two days in all cases. This timestamp doesn't get refreshed. In a typical application that means the user has to re-login after this time. That's also the maximum time frame a stolen session can be used.
The second value Frikandel::Configuration.ttl
states how long (in seconds) a session/cookie is valid, when the cookie timestamp gets not refreshed. The timestamp gets refrehed everytime a user visits the site.
The default values are 24.hours
for max_ttl
and 2.hours
for ttl
. If you are okay with this settings, you don't need to create an initializer for frikandel.
You can also overwrite what should happen when a cookie times out on the controller-level. The default behaviour is to do a reset_session
and redirect_to root_path
. For example, if you want to overwrite the default behavior when a user is on the PublicController
, you want to overwrite the on_invalid_session
-method in your controller:
class PublicController < ApplicationController
def on_invalid_session
raise "Your Session Has Expired! Oh No!"
end
end
If you want to revert the original behavior in a sub-class of your PublicController
, you simply re-alias the method to original_on_invalid_session
like this:
class AdminController < PublicController
alias on_invalid_session original_on_invalid_session
end
To run the test suite with different rails version by selecting the corresponding gemfile. You can use these one liners:
$ export BUNDLE_GEMFILE=gemfiles/rails-5.2.x.gemfile && bundle update && bundle exec rake spec
$ export BUNDLE_GEMFILE=gemfiles/rails-6.0.x.gemfile && bundle update && bundle exec rake spec
$ export BUNDLE_GEMFILE=gemfiles/rails-6.1.x.gemfile && bundle update && bundle exec rake spec
$ export BUNDLE_GEMFILE=gemfiles/rails-7.0.x.gemfile && bundle update && bundle exec rake spec
$ export BUNDLE_GEMFILE=gemfiles/rails-head.gemfile && bundle update && bundle exec rake spec
FAQs
Unknown package
We found that frikandel demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Rspack launches Rslint, a fast TypeScript-first linter built on typescript-go, joining in on the trend of toolchains creating their own linters.
Security News
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.