Description
Ruby on Rails applications using the default CookieStore session mechanism store session data entirely in client-side cookies without maintaining server-side session records. This design limitation prevents the server from truly invalidating sessions when users log out or when sessions are explicitly terminated. As a result, session cookies remain valid indefinitely until their expiration time, even after logout, allowing them to be replayed to regain authenticated access.
Remediation
Migrate from CookieStore to a server-side session storage mechanism that allows proper session invalidation. Implement one of the following solutions:
Option 1: Use ActiveRecord session store
Generate the session migration and configure Rails to use database-backed sessions:
rails generate session_migration rake db:migrateThen update
config/initializers/session_store.rb:YourApp::Application.config.session_store :active_record_store
Option 2: Use Redis or Memcached session store
Add the appropriate gem and configure session storage to use a centralized cache that supports expiration and deletion.
Additional hardening:
- Implement explicit session invalidation on logout by clearing server-side session records
- Set short session expiration times appropriate to your application's security requirements
- Rotate session identifiers after authentication and privilege changes
- Use secure cookie flags (HttpOnly, Secure, SameSite) to reduce cookie theft risk
References
Logout is broken by default in ruby on rails web applications
Ruby on Rails CookieStore Session Cookie Persistence Security Vulnerability