Skip to content

Use longer OAuth flow timeout for interactive frontend logins#4361

Open
reinkrul wants to merge 1 commit into
masterfrom
fix/4345-oauth-frontend-flow-timeout
Open

Use longer OAuth flow timeout for interactive frontend logins#4361
reinkrul wants to merge 1 commit into
masterfrom
fix/4345-oauth-frontend-flow-timeout

Conversation

@reinkrul

Copy link
Copy Markdown
Member

Fixes #4345.

Problem

The stateOAuthSession mapping for the OAuth authorization-code callback flows used a hard 1-minute TTL (oAuthFlowTimeout). That window has to cover the entire interactive round-trip: redirect to the external IdP, the user authenticating (password, MFA, consent), then the redirect back to the callback. For a human login that is too tight, so the callback failed with invalid_request "invalid or expired state".

Change

  • Add oauthFrontendFlowTimeout = 5 * time.Minute for interactive auth-code flows.
  • Apply it via storage.WithTTL(...) on the two interactive Puts:
    • OpenID4VCI auth-code (openid4vci.go)
    • OpenID4VP user login (user.go)
  • Back-end (service-to-service) flows (RFC021 VP-based, OpenID4VP verifier-side) keep the 1-minute oAuthFlowTimeout.

Both flow types share the same oauthClientStateStore. The store-level TTL is only a default; the actual expiry is set per entry at Put time, so the per-entry WithTTL cleanly distinguishes interactive from back-end entries and the callback reader (api.go) is unaffected — no need to split into two stores.

Notes

  • A longer TTL widens the replay window for a leaked state, but state is a single-use unguessable nonce consumed on first callback; 5 min is standard for auth-code flows.
  • No other caller relies on the 1-minute value (grep confirms only the two interactive Puts changed).

Assisted by AI

The state-to-OAuthSession mapping for the authorization-code callback
flows used a hard 1-minute TTL. That window has to cover the entire
interactive round-trip (redirect to the external IdP, user login/MFA/
consent, redirect back to the callback), which is too tight for a human
login and made the callback fail with "invalid or expired state".

Add oauthFrontendFlowTimeout (5 min) and apply it via WithTTL on the two
interactive auth-code flows (OpenID4VCI auth-code and OpenID4VP user
login). Back-end (service-to-service) flows keep the 1-minute
oAuthFlowTimeout. Both flows share the same store; the per-entry TTL
distinguishes them, so the callback reader is unaffected.

Assisted by AI
@qltysh

qltysh Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Qlty


Coverage Impact

⬆️ Merging this pull request will increase total coverage on master by 0.01%.

Modified Files with Diff Coverage (2)

RatingFile% DiffUncovered Line #s
Coverage rating: B Coverage rating: B
auth/api/iam/user.go100.0%
Coverage rating: A Coverage rating: A
auth/api/iam/openid4vci.go100.0%
Total100.0%
🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

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.

OAuth auth-code flow timeout too short for interactive frontend logins (1 min)

1 participant