Clarifying GitLab session behavior
Summary
Our session behavior is a bit confusing. This issue is a description of how it works today.
The outcome of this issue could be simplifying this behavior and/or documenting it more completely at https://docs.gitlab.com/ee/user/profile/#session-duration
Background
If you look at the issues in this epic: &9368
We have a lot of folks complaining about losing their sessions. Primarily on mobile.
This resulted in an exploration of our session behavior and any edge cases that may result from how things work today. Here is what I have learned so far.
"Remember me" checkbox during login
- Devise's
remember_forvalue defaults to 2 weeks - When a user logs in with
remember_mechecked, theremember_created_atattribute is set on that user record. - When a user logs in with
remember_mechecked, a persistent cookieremember_user_tokenis created in the browser. When you use the 'sign out' button thatremember_user_tokencookie is removed. - When a user is found via a cookie, Devise checks if the cookie "should be remembered" based on the value of
User#remember_created_atandremember_for - When the Devise
extend_remember_periodsetting istrue, the user's remember period is extended whenever the user is remembered via a cookie. We have this set totruefor GitLab.com - So, when a user sets
remember_me, their session cookie will be extended indefinitely as long as they are active within a 2 week period.
session_expire_delay Application Setting
We also have an application setting called session_expire_delay. That is used as follows:
-
current_userdefined in Devise - Calls to Warden's
authenticatemethod, which calls theset_usermethod - In
config/initializers/warden.rb, we callActiveSession.setwithin theWarden::Manager.after_set_userhook. -
ActiveSession.setsets the session expiry toSettings.gitlab['session_expire_delay'] * 60. -
Settings.gitlab['session_expire_delay']has a default value of10080, which is 1 week in minutes. - After leaving 'remember me' unchecked and quitting the browser, the browser forgets the
_gitlab_sessioncookie and is signed out. Note that the_gitlab_sessiontoken still exists in Redis so if an attacker gets your_gitlab_sessiontoken before it expires they still have full access.
Questions
- What happens if a user starts multiple sessions but doesn't have
remember_mechecked during a 2nd login? Does that cancelremember_mefor all of their sessions because in unsetsUser#remember_created_at? (I think it does. Which is...interesting and maybe unexpected). - Right now, the default value for
session_expire_delayis 1 week and the default value forremember_foris 2 weeks.. Ifremember meis checked during login, theremember_user_tokencookie is created and valid for up to 2 weeks of inactivity. But if a user is inactive for 1 week, their session will already be revoked due tosession_expire_delay...I think? If this is the case, we should update all docs references to being signed out after "2 weeks of inactivity" because it is really 1 week of inactivity. - I am a bit confused about why we have
session_expire_delayas an application setting that is separate fromremember_for(set via devise config) . These serve 2 different functions but it's confusing that a session could expire on a different timeline than the current user is remembered. This confusion is reflected in the docs here, which states "Stay signed in for two weeks: By default, you are signed out of GitLab after seven days (10080 minutes) of inactivity or until you close your browser window, whichever comes first."
Edited by Jessie Young