Skip to content

Extended session lifetime#9991

Open
pabzm wants to merge 1 commit intomasterfrom
extended-session-lifetime
Open

Extended session lifetime#9991
pabzm wants to merge 1 commit intomasterfrom
extended-session-lifetime

Conversation

@pabzm
Copy link
Member

@pabzm pabzm commented Sep 28, 2025

aka Persisted Login plugin functionality in core code.

Allows admins to set $config['extended_session_lifetime_days'], which allows users to switch on an extended session
lifetime in the login form. In effect, these user sessions are valid for the configured number of days even across
network outages, closed browsers (as long as they keep their cookies), etc.

Based on #9990

This would implement #5050

@pabzm pabzm changed the title Replace changed by expires_at in session handling PoC: extended session lifetime Sep 28, 2025
bin/gc.sh Outdated
$session_lifetime = $rcmail->config->get('session_lifetime', 0) * 60 * 2;

// Clean expired SQL sessions
if ($session_driver == 'db' && $session_lifetime) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems session_lifetime=0 might have been a valid use-case. However, I'm not sure how useful is that, so maybe we just drop it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to do that in another, dedicated PR, to make the change publicly and not "hidden" in another PR (just in case there are people out there who would like to jump in and explain their use case and why it shouldn't be removed).

base64_encode($newvars), $key);
} elseif ($ts - $this->changed > $this->lifetime / 2) {
$this->db->query("UPDATE {$this->table_name} SET `changed` = {$now}"
} elseif ($this->expires_at - $ts > $this->lifetime / 2) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering lifetime can be quite a big interval now. Maybe forcing an update at least every hour would make sense.

On the other hand. Isn't "Remember login for up to # days" imply that the session expiration should be not auto-extended? Also, is "up to" needed here? I guess these are some general questions we need to think about.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my understanding the feature is "X days after the last activity", which I tried to make clear with that wording.

@pabzm
Copy link
Member Author

pabzm commented Nov 10, 2025

Rebased onto #9990

@pabzm pabzm force-pushed the extended-session-lifetime branch from c263389 to 065e3f4 Compare November 10, 2025 08:58
@pabzm pabzm changed the title PoC: extended session lifetime Extended session lifetime Nov 10, 2025
@pabzm pabzm force-pushed the extended-session-lifetime branch from b3c084d to 1b02902 Compare November 10, 2025 14:57
@pabzm
Copy link
Member Author

pabzm commented Nov 10, 2025

Rebased again onto the latest changes from #9990

@pabzm pabzm force-pushed the extended-session-lifetime branch 2 times, most recently from 1748a3f to 125d63c Compare December 5, 2025 09:56
aka Persisted Login plugin functionality in core code.

Allows admins to set `$config['session_lifetime_extension_days']`, which
allows users to switch on an extended session lifetime in the login form.
In effect, these user sessions are valid for the configured number of days
after the last activity, even across network outages, closed browsers (as long
as they keep their cookies), etc.
@pabzm pabzm force-pushed the extended-session-lifetime branch from 125d63c to ce56fd9 Compare December 12, 2025 09:48
@pabzm
Copy link
Member Author

pabzm commented Dec 12, 2025

Squashed and rebased onto the latest state of the "master" branch.

@pabzm pabzm marked this pull request as ready for review December 15, 2025 13:44
// Warning: This reduces the effectiveness of Roundcube's session highjacking
// mitigation, since a stolen session cookie will be valid for much longer than
// without this option.
$config['session_lifetime_extension_days'] = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the code the default value is 0.


// Ignore checkboxes, they are prettified well enough by pretty_checkbox() already.
if (input.attr('type') === 'checkbox') {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we return here the tr will not get "form-group row" class, which makes it looking better (adds margin). Also, it would be good to align this row content to the center, imo.


if ($this->config->session_lifetime_extension_days() > 0) {
$session_lifetime_extension_hidden_field = new html_hiddenfield(['name' => '_session_lifetime_extension', 'value' => '0']);
$form_content['hidden']['session_lifetime_extension'] = $session_lifetime_extension_hidden_field->show();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hidden field isn't used, is it?

$session_lifetime_extension_text = str_replace('#', $this->config->session_lifetime_extension_days(), $this->app->gettext('session_lifetime_extension_switch_text'));
$session_lifetime_extension_checkbox = new html_checkbox(['name' => '_session_lifetime_extension', 'id' => '_session_lifetime_extension', 'title' => $session_lifetime_extension_text]);
$form_content['inputs']['session_lifetime_extension'] = [
'content' => html::label(['for' => '_session_lifetime_extension'], [$session_lifetime_extension_checkbox->show(), $session_lifetime_extension_text]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the checkbox is checked by default, it shouldn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants