Skip to content

PAR request URI lifespan is used as a hard cap on interactive login duration #51761

Closed

Description

@nxpthx

Before reporting an issue

  • I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

Area

oidc

Describe the bug

When a client uses Pushed Authorization Requests (RFC 9126), the realm setting PAR request URI lifespan (parRequestUriLifespan, default 60 s) does not only bound how long the request_uri reference may be redeemed at the authorization endpoint — it also silently bounds the maximum duration of the entire interactive authentication.

If the user needs longer than parRequestUriLifespan to complete login (MFA/OTP enrollment, e-mail verification, required actions such as UPDATE_PASSWORD or terms acceptance, identity-provider brokering, a slow user), the flow fails at authentication completion with:

KC-SERVICES0097: Invalid request: java.lang.RuntimeException: PAR not found, not issued or used multiple times.

The failure happens at authorization completion: the PAR payload is consumed before the authorization code is minted, so when the consume fails, no code is ever created and the browser is redirected back to the client with an error. The "Failure sequence" section below traces the exact ordering.

Raising parRequestUriLifespan to a value larger than the longest expected login makes the problem disappear, which confirms that the request-URI lifespan is being used as the login-duration limit.

This couples two independent concerns:

  1. the RFC 9126 request_uri lifetime (a bound on redemption of the reference at the authorization endpoint), and
  2. the maximum permitted interactive-authentication time, which Keycloak otherwise governs through the authentication session timeout.

Neither RFC 9126 nor RFC 6749 requires these to be the same value.

Version

26.7.1

Regression

  • The issue is a regression

Expected behavior

Once a valid, non-expired request_uri has been presented and accepted at the authorization endpoint and interactive authentication has started, completing that authentication should be governed by the authentication session timeout, not by parRequestUriLifespan.

parRequestUriLifespan should limit only:

  • how long the client may redeem the request_uri at the authorization endpoint (initiation), and
  • one-time-use / replay protection of the reference.

A user taking, say, 3 minutes to complete OTP setup should be able to finish a PAR-initiated login even with the default 60 s parRequestUriLifespan, provided the authentication session itself has not timed out.

Actual behavior

The PAR payload is stored in the single-use store with a TTL equal to parRequestUriLifespan and is only consumed at authentication completion, which happens before the authorization code is minted (see "Failure sequence"). Because the store entry is evicted after parRequestUriLifespan seconds regardless of flow state, any interactive login that runs longer than parRequestUriLifespan finds the entry already gone at completion. The consume throws INTERNAL_ERROR, code minting is never reached, and the login ends in an error instead of a redirect carrying a code.

How to Reproduce?

  1. Enable the par feature. Leave the realm PAR request URI lifespan at its default (60 s).
  2. Configure a client to use (or require) PAR.
  3. POST to the PAR endpoint and obtain a request_uri (+ expires_in: 60).
  4. Redirect the browser to /realms/{realm}/protocol/openid-connect/auth?client_id=...&request_uri=... and land on the login page.
  5. Wait longer than 60 s on the login page before submitting — or, more realistically, trigger a step that legitimately takes longer than 60 s (OTP enrollment, e-mail verification, an UPDATE_PASSWORD/terms required action, an IdP broker hop).
  6. Complete authentication.
  7. Observe the failure: authentication is aborted and the server log shows PAR not found, not issued or used multiple times. No code reaches the client's redirect_uri.
  8. Workaround: raise parRequestUriLifespan above the maximum expected login duration; the flow then completes.

Anything else?

The core problem: the single-use entry's TTL (ParEndpoint.java:186) equals parRequestUriLifespan, but the entry is not consumed until authenticationComplete(). So the entry's lifetime — intended to bound redemption of the reference — ends up bounding the whole interactive login. When login runs longer than parRequestUriLifespan, the entry is already evicted and completion fails.

Failure sequence — why no authorization code is issued

The decisive detail is the ordering inside [AuthenticationProcessor.authenticationComplete()](https://github.com/keycloak/keycloak/blob/428187f25ed36f620380631d0b8d0be40e0ef6c4/services/src/main/java/org/keycloak/authentication/AuthenticationProcessor.java#L1250-L1256): the PAR consume runs before the authorization code is minted.

  1. User completes interactive authentication. Elapsed time since the PAR was pushed is now greater than parRequestUriLifespan, so the single-use entry par:<key> has already been evicted.
  2. AuthenticationProcessor.authenticationComplete() calls loginProtocol.authenticationComplete(authSession) — [AuthenticationProcessor.java#L1252](https://github.com/keycloak/keycloak/blob/428187f25ed36f620380631d0b8d0be40e0ef6c4/services/src/main/java/org/keycloak/authentication/AuthenticationProcessor.java#L1252).
  3. That calls removeRequestObject(...), which returns null (entry gone) → OIDCLoginProtocol.authenticationComplete() throws AuthenticationFlowException(INTERNAL_ERROR) — [OIDCLoginProtocol.java#L587-L593](https://github.com/keycloak/keycloak/blob/428187f25ed36f620380631d0b8d0be40e0ef6c4/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java#L587-L593).
  4. Because step 3 throws, the very next line — [AuthenticationProcessor.java#L1255](https://github.com/keycloak/keycloak/blob/428187f25ed36f620380631d0b8d0be40e0ef6c4/services/src/main/java/org/keycloak/authentication/AuthenticationProcessor.java#L1255), AuthenticationManager.finishedRequiredActions(...) — is never reached.
  5. finishedRequiredActions() is the path that eventually calls [OIDCLoginProtocol.authenticated()](https://github.com/keycloak/keycloak/blob/428187f25ed36f620380631d0b8d0be40e0ef6c4/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java#L228) → [OAuth2CodeParser.persistCode(...)](https://github.com/keycloak/keycloak/blob/428187f25ed36f620380631d0b8d0be40e0ef6c4/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java#L280), i.e. where the authorization code is actually created. Since step 4 is skipped, persistCode() never runs and no code exists.
  6. The browser is redirected back to the client with an error rather than a code, so login fails and the client obtains no tokens.

Why this is a spec-level over-restriction, not a requirement

  • RFC 9126 §2.2 defines expires_in as the lifetime of the request_uri and expects it to be short (on the order of 5–600 s). It describes the request_uri as a single-use reference for the subsequent authorization request, and states explicitly that how the authorization server obtains the request data during the authorization process is at its discretion and out of scope. That leaves the server free to snapshot the data into the authentication session at first presentation.
  • RFC 9126 §4 requires one-time use of the request_uri and that an expired request_uri be rejected as invalid — i.e. at presentation at the authorization endpoint. It does not require the reference (or its backing data) to stay valid for the whole duration of interactive authentication, nor that authentication finish within expires_in.
  • RFC 9126 §7.3 recommends short-lived / one-time request_uri values to mitigate request-object replay. Forcing operators to inflate parRequestUriLifespan (e.g. to 30 min) purely to allow normal logins directly works against this recommendation — so "just raise the lifespan" trades away a security property to fix a usability bug.

Suggested direction

Decouple the interactive-authentication window from parRequestUriLifespan while preserving one-time-use and expiry-at-presentation:

Persist the PAR parameters into the authentication session when the request_uri is first accepted at the authorization endpoint, so completion no longer depends on the single-use entry

Related

Activity

  1. added
    kind/bug
    on Aug 17, 2026
  2. added theissue type on Aug 17, 2026
  3. added
    area/oidc
    on Aug 17, 2026
  4. mposolda commented on Aug 31, 2026

    @mposolda
    Contributor

    Thanks for the report. This needs to be fixed as it is a regression recently introduced by #48072 (although not a critical regression, but needs to be fixed).

  5. added a commit that references this issue on Sep 1, 2026
  6. added this to the 26.8 milestone on Sep 15, 2026
  7. 6 remaining items

  8. added a commit that references this issue on Sep 17, 2026
    74cd78d
  9. mposolda commented on Sep 17, 2026

    @mposolda
    Contributor

    Backported in 26.7 branch: 74cd78d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Fields

No fields configured for bug.

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions