Skip to content

OpenID Connect login survives a browser restart: option to tie the login to the browser session #13166

In progress

Description

@danabit

Description

After a login with OpenID Connect, closing the browser (all windows, browser process ended) and reopening it does not end the session: MapStore still shows the user as logged in, and the next token refresh restores the session without asking for credentials, as long as the IdP session is valid.

This also happens when the refresh_token cookie of GeoStore is a session cookie (geosolutions-it/geostore#606, fixed by geosolutions-it/geostore#609 with refreshTokenCookieMaxAge=-1), because MapStore persists the security state, including the access token, in localStorage (mapstore.persistence.security), which survives the browser restart. On a shared computer, the next person who opens the browser can use the application with the previous user's identity, if that user closed the browser without logging out.

As suggested in geosolutions-it/geostore#606, we are opening the issue here.

Proposal: a configuration option in localConfig.json (for example in the security section) to choose where the security state is persisted:

  • localStorage: current behavior, default;
  • browser session: sessionStorage or another session-scoped mechanism shared by the tabs of the same browser session (for example a session cookie used as a marker), so that the state is discarded after a browser restart;
  • no persistence of the token.

When the state is discarded, MapStore should also end the session on the server side (GeoStore and, where configured, the IdP), so that the next refresh cannot restore it.

What kind of improvement you want to add?

  • Minor changes to existing features

Other useful information

Environment: MapStore 2026.03.00 (GeoStore 2.7.0); OpenID Connect login with Keycloak 26 (keycloakOAuth2Config), confidential client with PKCE; access token 5 minutes, SSO session idle 30 minutes, SSO session max 8 hours.

Steps to reproduce:

  1. Use a browser profile that does not restore the previous session at startup and does not keep running in background.
  2. Log in to MapStore with an OpenID Connect provider (Keycloak).
  3. Close the browser completely, without logging out.
  4. Reopen the browser and open MapStore: the user is still logged in.
  5. Wait for the next refreshToken call: it succeeds and the session goes on (with a session refresh_token cookie, the cookie is set again).

Private (incognito) windows are not a good test case, because the browser clears all storage when they are closed.

Current workaround: in our project we are adding an epic that sets a session cookie as a "browser session" marker after the login. When the page loads with a persisted login but without the marker, it performs a full logout (MapStore and the IdP) and shows a notice. We would be happy to drop it in favor of a standard option.

Related: geosolutions-it/geostore#606, geosolutions-it/geostore#609.

Activity

  1. danabit commented on Nov 18, 2026

    @danabit
    Author

    Additional finding: when the token refresh fails, refreshAccessToken dispatches logout(null), which only clears the local state. DELETE /session/logout is sent only by onLogout (the Logout button), so the GeoStore and IdP sessions are not ended. With geosolutions-it/geostore#613 GeoStore can now end the IdP session even with an expired access token, so it would help if MapStore called the server logout in this case too.

  2. added this to the 2026.03.01 milestone on Nov 18, 2026
  3. added theissue type on Nov 18, 2026
  4. afabiani commented on Nov 18, 2026

    @afabiani
    Member

    #13171 covers both points, for 2026.03.01 (it is marked for backport to 2026.03.xx):

    • A new localConfig.json option, loginPersistence: local (the default, as today) or browserSession. With browserSession, a session cookie marks the browser session at login. A stored login without it is not restored after a browser restart: MapStore starts logged out and sends DELETE /session/logout with the stored access token. The login is still shared by the tabs and survives page reloads. Logins made before the option is turned on end at their next page load.
    • When a token refresh fails, MapStore now also sends DELETE /session/logout with the token it held, whatever the setting.

    With GeoStore 2.7.1 (geosolutions-it/geostore#611 and geosolutions-it/geostore#613) and globalLogoutEnabled=true, that logout also ends the Keycloak session, even when the access token has already expired. I tested it in Chromium against Keycloak 26, simulating a browser restart: with browserSession the Keycloak session ends, and with the default setting a failed refresh after the restart now ends it as well. Browsers set to restore the previous session at startup also restore session cookies, so with them the login is kept.

    This should let you drop your marker epic once you are on these versions; unlike it, MapStore does not show a notice. If you can try #13171 in your project, let me know how it goes.

  5. afabiani commented on Nov 18, 2026

    @afabiani
    Member

    One more thing about the refresh, which matters with very short access tokens. GeoStore refuses a refresh once the access token has expired (403), and it renews the token only in the last part of its lifetime: refreshTokenLifetimeFraction is 0.8 by default, so the last 20%. MapStore asks for a refresh every 30 seconds (tokenRefreshInterval).

    With your 5-minute tokens that window is 60 seconds, so MapStore always catches it. With tokens shorter than about two and a half minutes it can miss it, and the session ends at the first expiry; in my tests with 60-second tokens it did. That was already the case before, but with #13171 such a failure also ends the Keycloak session, so the user is asked for credentials again instead of being logged in silently. If you ever shorten the token lifetime, lower tokenRefreshInterval in localConfig.json or oidcOAuth2Config.refreshTokenLifetimeFraction in geostore-ovr.properties to match.

  6. 2 remaining items

  7. afabiani commented on Nov 18, 2026

    @afabiani
    Member

    Added to #13171: MapStore now dispatches SESSION_ENDED (web/client/actions/security.js) with reason set to browserSession when a stored login of an earlier browser session is not restored, or refreshFailed when the token refresh fails; SESSION_END_REASONS holds both values. The first is dispatched on the first location change after startup, so an epic in your project's plugins receives it. The Logout button does not dispatch it.

    I checked the three cases in the browser: a restart with browserSession gives SESSION_ENDED with browserSession and no LOGOUT, a failed refresh gives LOGOUT followed by SESSION_ENDED with refreshFailed, and the Logout button gives LOGOUT only.

  8. danabit commented on Nov 18, 2026

    @danabit
    Author

    Thanks a lot, SESSION_ENDED with the reason is exactly what we needed: with 2026.03.01 we will keep only our notice, based on that action, and drop the rest of our code. We will test it when the release is out.

  9. added a commit that references this issue on Nov 23, 2026
  10. self-assigned this
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions