Skip to content

fix: harden session refresh and logout #111

Closed

Description

@uniqueg

Found in the pre-release review of Krini 0.1.0. Session handling with a real identity provider has several gaps that should be fixed before the tag. This issue also covers #106 (a refresh in flight can undo the logout).

Why

  1. Refresh errors don't follow RFC 6749. POST /auth/api/refresh ends the session (clears cookies, applies the replay window) only when the token endpoint answers 401. RFC 6749 §5.2 uses 400 invalid_grant for an expired, revoked or reused refresh token and 401 only for invalid_client. So a dead refresh token never ends the session, and a rotated client secret (401 invalid_client) wipes every user's session.
  2. One status for every failure. The route answers 401 to everything (no refresh token, IdP 503, timeout), and useTokenRefresh sends the tab to /auth/login on any error. A short IdP outage sends every open tab to the login page and loses unsaved form input.
  3. Stale token_expires_at. The cookie lives for a fixed 30 days and is never deleted, so after a session ends without logout every dashboard visit, including anonymous ones, redirects to /auth/login until it expires. The stored value is also shifted by 5 minutes, and the hook subtracts another 5, so the refresh fires about 10 minutes early.
  4. Refresh after logout restores the session (fix: a refresh in flight can undo the logout #106). A refresh response that arrives after the logout response sets the session cookies again; /auth/api/token and /auth/api/user-info don't check logout_marker, and logout doesn't stop the refresh timer. The existing unit test mutates the request's own cookie jar and doesn't test the real race.
  5. id_token cookie can expire before the session. It gets the access token's max-age and is rewritten only if the refresh response has an ID token (optional per OIDC Core 12.2). Once it's gone, the user menu shows "Anonymous" and the compute UI is hidden, although the tokens are valid. A refreshed ID token's sub/iss aren't compared with the session's.
  6. Smaller gaps: POST /auth/api/refresh has no Origin check (logout has one); the refresh_token cookie's max-age isn't capped at the 30 days the privacy notice promises; the docs say concurrent refreshes across pods "can log the user out", while the actual effect is a redirect to the login page (related: fix: concurrent refreshes log users out #93, fix: share the refresh replay check across pods #107); no tests cover refresh failures, and the e2e mock always answers 200 to the refresh_token grant.

Expected result

  • 400 invalid_grant (and 401) from the token endpoint end the session: all session cookies are cleared (unless the replay window applies) and the route answers 401
  • invalid_client and other provider or network errors keep the cookies, are logged, and the route answers 503
  • The hook retries transient errors with backoff, redirects to login only when the session is over, and never redirects anonymous visitors; no refresh token clears token_expires_at without a redirect
  • token_expires_at stores the real access token expiry and lives as long as the session
  • A refresh that finishes after the logout doesn't restore the session; token and user-info refuse requests after logout; logout stops the refresh timer and waits for a refresh in flight
  • id_token lives as long as the session; a refreshed ID token with a different sub or iss is rejected
  • The refresh route checks the Origin like logout; the refresh_token max-age is capped at 30 days
  • Docs updated: login.md, helm-chart.md, upgrading.md, values.yaml, privacy notice
  • Unit tests for each case, and a refresh-failure mode in the e2e mock with e2e tests

Activity

  1. added this to the v0.1.0 milestone on Nov 19, 2026
  2. added
    priority: high
    status: in progress
    on Nov 19, 2026
  3. self-assigned this
    on Nov 19, 2026
  4. added
    type: bug
    workload: hours
    on Nov 19, 2026
  5. moved this from Backlog to In progress in ELIXIR On-Cloudon Nov 19, 2026
  6. moved this from In progress to In review in ELIXIR On-Cloudon Nov 19, 2026
  7. moved this from In review to Done in ELIXIR On-Cloudon Nov 19, 2026
  8. removed
    status: in progress
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority: hightype: bugworkload: hours

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions