diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-24 17:20:41 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-24 17:20:41 +0200 |
| commit | d5883869e97244335370d54e21ef46b3f1885899 (patch) | |
| tree | 4575a24150f4c2fa98de54fdd556132f0aa0ff8c /lib/authenticated_system.rb | |
| parent | 0d2a8e4b61f4b79507519c73f127b7ab883d853c (diff) | |
Give all sessions a uniform absolute lifetime of one week
Enforced at restore via a login-time stamp, written only at genuine
logins so the limit stays absolute rather than sliding. The cookie
name rotation logs everyone out once at deploy. Second-factor users
are deliberately not treated worse than password-only ones.
Diffstat (limited to 'lib/authenticated_system.rb')
| -rw-r--r-- | lib/authenticated_system.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/authenticated_system.rb b/lib/authenticated_system.rb index 7accfaaa..2ec15a77 100644 --- a/lib/authenticated_system.rb +++ b/lib/authenticated_system.rb | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | module AuthenticatedSystem | 1 | module AuthenticatedSystem |
| 2 | SESSION_MAX_AGE = 7.days | ||
| 3 | |||
| 2 | protected | 4 | protected |
| 3 | # Returns true or false if the user is logged in. | 5 | # Returns true or false if the user is logged in. |
| 4 | # Preloads @current_user with the user model if they're logged in. | 6 | # Preloads @current_user with the user model if they're logged in. |
| @@ -98,7 +100,12 @@ module AuthenticatedSystem | |||
| 98 | 100 | ||
| 99 | # Called from #current_user. First attempt to login by the user id stored in the session. | 101 | # Called from #current_user. First attempt to login by the user id stored in the session. |
| 100 | def login_from_session | 102 | def login_from_session |
| 101 | self.current_user = User.find_by_id(session[:user_id]) if session[:user_id] | 103 | return unless session[:user_id] |
| 104 | if session[:logged_in_at].to_i > SESSION_MAX_AGE.ago.to_i | ||
| 105 | self.current_user = User.find_by(:id => session[:user_id]) | ||
| 106 | else | ||
| 107 | session[:user_id] = nil | ||
| 108 | end | ||
| 102 | end | 109 | end |
| 103 | 110 | ||
| 104 | # | 111 | # |
