Skip to content

Logout when the last tab is closed

When a user closes the last browser tab of the platform, their session stays open until it expires: by default, 20 minutes later (app:session_timeout). Anyone who reopens the platform from the same browser during that time is still logged in.

With Logout when the last tab is closed, the platform logs the session out shortly after its last tab is closed.

Enable the logout

Go to Settings > Security > Authentications, and find Logout when the last tab is closed in the Sessions card. You need the Manage authentication capability (SETTINGS_SETAUTH).

The setting is off by default. It applies to every user of the platform, from the moment it is turned on: the tabs already open are taken into account within about 10 seconds, without reloading them.

Under the switch, Grace period before logout shows the grace period in use. It is read-only: change it with app:session_presence:grace_period in the platform configuration (see Configuration).

With an Enterprise Edition license, every change of this setting is recorded in the activity log.

Upgrade every node first

On a platform with several nodes, turn the setting on only once every node runs a version that supports it. A node without the support does not report its tabs: a user whose remaining tabs are connected to it could be logged out while they still work.

How it works

  1. Each open tab keeps a connection with the platform (the WebSocket of the live updates). The platform counts the connections of each session, on all its nodes.
  2. When the last connection of a session closes, a grace period starts: 30 seconds by default (app:session_presence:grace_period).
  3. If a tab of the session connects again before the end of the grace period, nothing happens. This covers a page reload, a navigation that opens a new tab, or a short network loss.
  4. At the end of the grace period, the session is logged out. The next request from this browser goes to the login page.

With the default configuration, a session is usually logged out between 30 and 35 seconds after its last tab is closed (the check runs every 5 seconds). Each check logs out at most 100 sessions: when more sessions lose their last tab at the same time, the others are logged out at the next checks, 5 seconds later each.

When the browser cannot close its tabs

A tab does not need to be closed properly. When the computer goes to sleep, or loses its network, the platform stops receiving answers on the connection and closes it within about 24 seconds. The grace period then starts: with the default configuration, the session is logged out about one minute after the computer went to sleep.

When the computer wakes up, its tabs show the login page.

What is logged out

  • Only the session whose last tab was closed. The other sessions of the same user, on other browsers or other computers, are not affected.
  • Only the session in the platform. The logout is not sent to the identity provider (SAML, OpenID Connect...): the user stays logged in there. With a single sign-on that logs in without asking for credentials, opening the platform again may log the user back in at once, without any action from them.

What is not logged out

  • A session that never opened a tab: for instance, a session used by a script. It only ends when it expires.
  • A session whose tabs cannot open the connection, for instance behind a proxy that blocks WebSockets. It only ends when it expires.
  • The API tokens: they do not use sessions.

Audit

With an Enterprise Edition license, each logout is recorded in the activity log, like a logout from the user menu: an authentication event, logout scope, with reason: last_tab_closed in its context data. It is recorded for the user of the session, with the IP address and the browser of their latest tab.

Requirements

The logout is done by the session presence manager. If the setting is on while the logout cannot apply, the settings page shows a warning:

Warning Cause What to do
The session presence manager is disabled on every platform node session_presence_manager:enabled is false on every node Enable the manager on at least one node
Several platform nodes serve the API app:session_manager is local, and more than one node serves the API: a node cannot log out the sessions held in the memory of another node Use the shared session store (app:session_manager: shared, the default), or a single node for the API

When the manager is disabled, nothing is logged out: the abandoned sessions only expire as usual.

Several nodes

With the shared session store, the tabs of a session can be connected to different nodes, and any node running the manager logs out any session. Only one node runs the manager at a time (Redis lock).

When a node stops, during a rolling restart for instance, its tabs connect again to another node. The connections of the stopped node are kept for app:session_presence:lease_ttl (30 seconds by default), then the grace period starts. A session keeps going if one of its tabs connects again to another node within this time (about one minute with the default configuration). A session whose tabs cannot connect again in time, for instance because no other node is available, is logged out as if its tabs had been closed.

Configuration

Parameter Environment variable Default value Description
app:session_presence:grace_period APP__SESSION_PRESENCE__GRACE_PERIOD 30000 (30 s) Time in milliseconds between the closing of the last tab of a session and its logout. A tab that connects again within this time keeps the session.
app:session_presence:lease_ttl APP__SESSION_PRESENCE__LEASE_TTL 30000 (30 s) Time in milliseconds a connection is kept when its node stops reporting it (stopped or crashed node). Each node reports its connections every third of this time.
session_presence_manager:enabled SESSION_PRESENCE_MANAGER__ENABLED true Enable/disable the session presence manager, which logs out the sessions. With app:session_manager: local, it only runs on a node that serves the API.
session_presence_manager:lock_key SESSION_PRESENCE_MANAGER__LOCK_KEY session_presence_manager_lock Lock key of the manager in Redis
session_presence_manager:interval SESSION_PRESENCE_MANAGER__INTERVAL 5000 Interval in milliseconds between two checks of the abandoned sessions

A shorter grace period logs out sooner, but a slow page reload or a short network loss may then log the user out.

Monitoring

The platform exports these metrics (see Telemetry):

Metric Type Description
opencti_session_presence_connections Gauge Number of tab connections tracked by the node
opencti_session_presence_last_disconnections Counter Sessions left without any tab connection, starting their grace period
opencti_session_presence_checks Counter Checks of the abandoned sessions, by result (opencti.session_presence.result): alive (a tab came back, or the grace period is not over), logout, released (session already ended, or setting off)