Skip to content

fix: handle expired sessions safely across console tabs - #300

Merged
cxymds merged 1 commit into
mainfrom
cxymds/fix-session-expiry
Nov 14, 2026
Merged

cxymds merged 1 commit into
mainfrom
cxymds/fix-session-expiry

Conversation

@cxymds

@cxymds cxymds commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Pull Request

Description

Expired STS credentials could leave Console on an error page, and a delayed request from another tab could delete a newly established session. Authentication failures now invalidate only the session that signed the request, and idle sessions return to Login with the existing expiration notice.

  • Handle JSON/XML InvalidAccessKeyId, ExpiredToken (including HTTP 400), and existing unauthorized responses consistently in Admin and S3 clients. Permission errors retain their normal handling.
  • Persist credential changes synchronously, read the latest session before invalidation, and hide clients until they match the current credentials.
  • Check expiration with a bounded timer and on browser visibility/page restoration. Preserve manual OIDC logout and show the expiration warning once.
  • Reject a login that cannot save credentials instead of creating an untracked in-memory session.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test improvements
  • Security fix

Testing

  • Unit tests added/updated
  • Manual testing completed
nvm use v22
pnpm install --frozen-lockfile
pnpm type-check
pnpm lint
pnpm format:check
pnpm test:run
pnpm build
git diff --check

All checks passed; 1,059 tests passed. Regression coverage includes delayed API/S3 errors and timers before/after storage events, replacement-client readiness, JSON/XML authentication errors, ordinary AccessDenied, storage failures, idle expiration, and OIDC logout. S3 tests exercise the real AWS SDK with simulated HTTP responses.

Chrome validation against a local simulated RustFS API covered expired bucket refresh, a 10-second idle session at a 390 × 844 mobile viewport, and two tabs retaining the replacement session after an old request's delayed 403 was released.

Checklist

  • Code follows the project's style guidelines
  • Self-review completed
  • TypeScript types are properly defined
  • All commit messages are in English (Conventional Commits)
  • All existing tests pass
  • No new dependencies added, or they are justified

Related Issues

Closes #299

Screenshots (if applicable)

Browser captures use the local simulated API described above. The desktop pair shows the same expired bucket-refresh flow before and after the fix; additional captures cover idle mobile expiration and both tabs after the delayed old response.

Desktop expired refresh, before / after:

Expired bucket refresh before and after

Idle expiration on mobile:

Idle session expiration on mobile

Both tabs after releasing the old request’s delayed 403:

Replacement session remains active in both tabs

Additional Notes

Independent correctness, test, simplification, and UX reviews were completed. No live RustFS VM deployment or Firefox/Authelia OIDC integration run was performed.

Scope failure callbacks and client readiness to their STS session so delayed requests cannot erase a replacement login. Unify API and S3 authentication errors, detect idle expiration, and preserve explicit OIDC logout.
Copilot AI balanced review requested due to automatic review settings November 13, 2026 23:54
@cxymds
cxymds merged commit f1efd4a into main Nov 14, 2026
11 checks passed
@cxymds
cxymds deleted the cxymds/fix-session-expiry branch November 14, 2026 00:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical cross-tab race allows logout to delete replacement login credentials and the OIDC token because the session check and deletion are not atomic across tabs.

1 open issue
What changed in this PR

This PR addresses #299 by improving expired-session handling across Console tabs, Admin requests, and S3 requests while preserving manual OIDC logout.

Changes:

  • Recognizes session errors consistently and checks the current session before invalidation.
  • Persists credentials synchronously, hides outdated clients, and checks expiration during idle periods and browser restoration.
  • Shows the expiration warning once and expands regression coverage.
File Description
tests/​lib/​s3-error-middleware.test.ts Adds SDK-backed error and response coverage.
tests/​lib/​form-interaction.test.ts Tests expiration warnings and recovered-session redirects.
tests/​lib/​auth-session.test.ts Tests credential validity and session identity.
tests/​lib/​api-client.test.ts Covers authentication errors and permission handling.
tests/​hooks/​use-oidc-logout.test.ts Expands cross-tab, timer, persistence, and logout coverage.
lib/​s3-error-middleware.ts Extracts S3 error handling and propagates session failures.
lib/​auth-session.ts Adds shared session validation and error classification.
lib/​api-client.ts Unifies Admin authentication-error handling.
hooks/​use-local-storage.ts Makes persistence synchronous and reloads current storage values.
contexts/​s3-context.tsx Binds S3 clients and invalidation to session credentials.
contexts/​auth-context.tsx Adds conditional invalidation and automatic expiration checks.
contexts/​api-context.tsx Guards stale callbacks and exposes matching clients only.
app/​(auth)/​auth/​login/​page.tsx Prevents duplicate or obsolete expiration warnings.

Review effort: Balanced

Comment thread contexts/auth-context.tsx
Comment on lines +234 to +235
if (loggingOutRef.current || !isCurrentSession(expected)) return false
logout()
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.

[BUG] Console: expired sessions are not handled consistently

2 participants