Skip to content

fix(oidc): guard against zero/negative token expiry in session TTL#92

Open
s0up4200 wants to merge 2 commits into
developfrom
fix/oidc-session-expiry
Open

fix(oidc): guard against zero/negative token expiry in session TTL#92
s0up4200 wants to merge 2 commits into
developfrom
fix/oidc-session-expiry

Conversation

@s0up4200
Copy link
Copy Markdown
Collaborator

@s0up4200 s0up4200 commented Mar 7, 2026

Summary

  • When an OIDC provider returns a token without expires_in (or with an already-past expiry), token.Expiry is the Go zero time, making time.Until() return a large negative duration
  • This caused sessions to be stored with an already-expired TTL and cookies with a negative max-age, resulting in an infinite redirect loop on /login after successful authentication with the OIDC provider
  • Falls back to a 24h TTL when the computed session TTL is non-positive

Details

The OIDC callback handler used time.Until(token.Expiry) in three places:

  1. Cache TTL for the session
  2. ExpiresAt field in SessionData
  3. Cookie max-age

If the provider omits expires_in from the token response, the oauth2 library leaves Token.Expiry as the zero value (0001-01-01T00:00:00Z). time.Until(zeroTime) produces a massive negative duration, causing:

  • The cache item to be stored with an already-past expiration (immediately treated as expired on Get())
  • The cookie to have a negative max-age (browser may discard it)

Observed with Authentik as the OIDC provider — after successful authentication, the frontend's /api/auth/oidc/verify call would find no session, triggering a redirect loop.

🤖 Generated with Claude Code

s0up4200 and others added 2 commits March 7, 2026 17:26
When an OIDC provider returns a token without expires_in (or with an
already-past expiry), token.Expiry is the Go zero time, making
time.Until() return a large negative duration. This caused sessions to
be stored with an already-expired TTL and cookies with a negative
max-age, resulting in an infinite redirect loop on /login after
successful authentication.

Fall back to a 24h TTL when the computed session TTL is non-positive.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant