Expired native Login/Registration use_flow_id loses the session-token exchanger
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 foundThe 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:
selfservice:
flows:
login:
lifespan: 5s- Create a native Login Flow:
GET /self-service/login/api
?return_session_token_exchange_code=true
&return_to=<allowed-native-callback>Retain:
{
"id": "<original-flow-id>",
"session_token_exchange_code": "<init-code>"
}Wait until
expires_at.Submit an OIDC provider using the exact provider value offered by the Flow:
POST /self-service/login?flow=<original-flow-id>
Accept: application/json
Content-Type: application/json
{
"method": "oidc",
"provider": "<provider-node-value>"
}- Kratos returns HTTP 410:
{
"error": {
"id": "self_service_flow_expired"
},
"use_flow_id": "<replacement-flow-id>"
}- Fetch the replacement and submit the same OIDC provider:
GET /self-service/login/flows?id=<replacement-flow-id>POST /self-service/login?flow=<replacement-flow-id>
Accept: application/json
Content-Type: application/json
{
"method": "oidc",
"provider": "<provider-node-value>"
}Follow the returned
redirect_browser_toin a browser cookie context separate from the API client, as a native application does.Complete authentication with the provider.
Actual behavior
The callback fails with:
no resumable session foundNo 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:
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_aalrefresh- 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.
Source: ory/kratos