#4610·kratos

Expired native Login/Registration use_flow_id loses the session-token exchanger

Author: robingulloCreated Sep 18, 2026Updated Sep 18, 2026
LabelsNeeds Triage

Description

When a native Login or Registration Flow created with return_session_token_exchange_code=true expires, Kratos returns HTTP 410 with a replacement use_flow_id.

Following that replacement Flow for OIDC authentication fails after the browser callback with:

no resumable session found

The replacement Flow is not associated with the original session-token exchanger. Consequently, OIDC state is generated without the native exchange-code binding, and the callback incorrectly falls back to cookie continuity.

This also affects SAML providers implemented through the same OIDC strategy.

Reproduction

Configure a short Flow lifespan:

yaml
selfservice:
  flows:
    login:
      lifespan: 5s
  1. Create a native Login Flow:
http
GET /self-service/login/api
    ?return_session_token_exchange_code=true
    &return_to=<allowed-native-callback>

Retain:

json
{
  "id": "<original-flow-id>",
  "session_token_exchange_code": "<init-code>"
}
  1. Wait until expires_at.

  2. Submit an OIDC provider using the exact provider value offered by the Flow:

http
POST /self-service/login?flow=<original-flow-id>
Accept: application/json
Content-Type: application/json

{
  "method": "oidc",
  "provider": "<provider-node-value>"
}
  1. Kratos returns HTTP 410:
json
{
  "error": {
    "id": "self_service_flow_expired"
  },
  "use_flow_id": "<replacement-flow-id>"
}
  1. Fetch the replacement and submit the same OIDC provider:
http
GET /self-service/login/flows?id=<replacement-flow-id>
http
POST /self-service/login?flow=<replacement-flow-id>
Accept: application/json
Content-Type: application/json

{
  "method": "oidc",
  "provider": "<provider-node-value>"
}
  1. Follow the returned redirect_browser_to in a browser cookie context separate from the API client, as a native application does.

  2. Complete authentication with the provider.

Actual behavior

The callback fails with:

no resumable session found

No native return_to code is produced, so the client cannot exchange it with its original session_token_exchange_code.

Using the same cookie jar for both API requests and browser navigation may mask the problem and does not reproduce normal native-app behavior.

Expected behavior

The replacement referenced by use_flow_id should remain attached to the original session-token exchanger.

After OIDC completion, Kratos should redirect to the native return_to with a return code, and this should succeed:

http
GET /sessions/token-exchange
    ?init_code=<original-init-code>
    &return_to_code=<callback-code>

Root cause

Native Flow creation creates an exchanger keyed by the initial Flow ID:

Expired-flow replacement calls FromOldFlow:

These functions neither create an exchanger nor call MoveToNewFlow. The exchanger therefore remains keyed by the expired Flow.

When OIDC starts on the replacement, CodeForFlow(replacement.ID) finds nothing:

The callback then selects cookie continuity instead of native exchange-code continuity:

Kratos already has MoveToNewFlow, used for OIDC Login↔Registration transitions:

Additional replacement-context concerns

FromOldFlow creates and hydrates the replacement from the update request, then copies only RequestURL and IdentitySchema. It does not reliably preserve:

  • requested_aal
  • refresh
  • organization
  • OAuth2 login challenge
  • internal context
  • active method
  • Flow state
  • transient payload

Furthermore, IdentitySchema is copied after node hydration, so the stored schema and generated nodes can disagree.

RequestURL, and therefore generally return_to, is preserved.

These may deserve separate issues, but the missing exchanger alone is sufficient to reproduce the native OIDC failure.

Versions inspected

The replacement behavior is present from Kratos v1.0.0 through v26.2.0 and in public master at b86338da04a040247a07f46100a86dcfb3875909.