Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new option for configurable cookie lifetime #7709

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion config/defaults.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,13 @@
// 0 - hide product name and version number, 1 - show product name only, 2 - show product name and version number
$config['display_product_info'] = 1;

// Session lifetime in minutes
// Session lifetime in minutes (server side)
$config['session_lifetime'] = 10;

// Cookie lifetime in minutes for session id and auth cookies
// 0 - session cookies (expire on browser exit)
$config['cookie_lifetime'] = 0;

// Session domain: .example.org
$config['session_domain'] = '';

Expand Down
4 changes: 2 additions & 2 deletions program/lib/Roundcube/rcube.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ public function session_init()
$sess_path = $this->config->get('session_path');
$sess_samesite = $this->config->get('session_samesite');
$lifetime = $this->config->get('session_lifetime', 0) * 60;
$c_lifetime = $this->config->get('cookie_lifetime', 0) * 60;
$is_secure = $this->config->get('use_https') || rcube_utils::https_check();

// set session domain
Expand All @@ -464,8 +465,7 @@ public function session_init()
ini_set('session.gc_maxlifetime', $lifetime * 2);
}

// set session cookie lifetime so it never expires (#5961)
ini_set('session.cookie_lifetime', 0);
ini_set('session.cookie_lifetime', $c_lifetime);
ini_set('session.cookie_secure', $is_secure);
ini_set('session.name', $sess_name ?: 'roundcube_sessid');
ini_set('session.use_cookies', 1);
Expand Down
5 changes: 4 additions & 1 deletion program/lib/Roundcube/rcube_session.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,11 @@ function check_auth()
*/
public function set_auth_cookie()
{
$clifetime = $this->config->get('cookie_lifetime', 0) * 60;
if (!$clifetime) { $expiration = 0; }
else { $expiration = time() + $clifetime; }
$this->cookie = $this->_mkcookie($this->now);
rcube_utils::setcookie($this->cookiename, $this->cookie, 0);
rcube_utils::setcookie($this->cookiename, $this->cookie, $expiration);
$_COOKIE[$this->cookiename] = $this->cookie;
}

Expand Down