You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IdP errors with SessionNotFound on stale session cookies instead of expiring + restarting the interaction #526
After re-provisioning a pod (or otherwise rotating cookie-signing keys), a browser that still holds an old _session / _interaction cookie for the IdP origin fails sign-in at the consent / "Allow access" step. provider.interactionFinished(...) throws and the request 400s:
SessionNotFound: invalid_request — "session not found"
at #getInteraction (oidc-provider/lib/provider.js)
at Provider.interactionResult / interactionFinished
"Promise errored, but reply.sent = true was set"
Login + the interaction pages all succeed; only the final confirm (interactionFinished) dies. The user is stuck until they manually clear site data for the IdP origin. Incognito works (no stale cookie), which pinpoints it.
Repro
Sign in to a pod, leave the browser cookies in place.
Re-provision / reinstall so the persisted cookie keys change (or the stored session/interaction is gone).
Sign in again from the same (non-incognito) browser → reaches consent → "Allow access" → SessionNotFound.
(Surfaced repeatedly during the Android app dev cycle — js-pod/android — across reinstalls; a fresh user wouldn't hit it, but a reinstall does.)
Why it matters
A stale cookie shouldn't be a dead end. The user has no in-app way to recover; they have to know to clear site data, which a normal user won't.
Existing precedent (the fix is small)
JSS already handles the analogous deleted-account case and already has the helpers:
src/idp/provider.js:268,407,420 — guard that, when a session/grant is missing due to stale cookies, calls expireSessionCookiesKoa(ctx) and redirects back to retry.
src/idp/cookies.js — expireSessionCookies(reply, request) and expireSessionCookiesKoa(ctx).
src/idp/interactions.js:221-224 — already wraps one interactionFinished in try/catch with a fallback ("interactionFinished failed, using fallback").
Proposed fix
In the interaction handlers that call provider.interactionFinished(...) (src/idp/interactions.js — the /confirm path via src/idp/index.js:408, plus the other call sites at lines ~166, 289, 606, 644, 823), catch SessionNotFound (err.name === 'SessionNotFound') and, instead of erroring, expire the session/interaction cookies and 303 back to the authorization URL to restart the interaction cleanly — mirroring the existing deleted-account guard. Net effect: a stale cookie self-heals into a fresh login instead of a 400.
PR #539 (closes #412) lands a partial of the fix proposed here — scoped to handleSchnorrComplete only, and using the simpler Approach C (return a 4xx error page) rather than the auto-healing 303-redirect-and-restart shape this issue proposes.
The 504 hang on schnorr-complete is gone (turns into a 400 with a "restart login" page).
The other four sites still hang on missing-cookie.
None of them yet self-heal via the cookie-expire + redirect pattern this issue calls out.
This issue stays load-bearing for the remaining work. The mechanical shape is the same across all five — could be a single helper, e.g. await finishOrExpireAndRetry(reply, request, provider, returnTo, ...), with the four sites consolidating onto it.
(Almost filed a separate "sweep" issue when working on #412; the dupe search caught this one — leaving the cross-reference here so the relationship is documented.)
Update: foundation landed across all 5 sites in #540
PR #540 (squash-merged as 9051737) extracted the defensive recovery pattern into a single helper finishInteractionDefensively and replaced all fivereply.hijack(); return provider.interactionFinished(...) sites in src/idp/interactions.js with calls to it.
So the previous status comment is now stale — every interaction handler is now hang-proof on SessionNotFound:
handleConsent (the "Allow access" path this issue originally describes)
✅ helper-backed
handlePasskeyComplete
✅ helper-backed
handlePasskeySkip
✅ helper-backed
What this issue still owns
The UX upgrade from "show a 400 error page" → "self-heal via expireSessionCookies + 303 to the authorization URL". The helper is now the single place to add that logic — once this issue gets the work, finishInteractionDefensively grows an extra branch (or the SessionNotFound branch swaps errorPage for an expireSessionCookies(reply, request); reply.raw.writeHead(303, { Location: <authUrl> })), and all five handlers inherit it for free.
Sketch for whoever picks this up
// inside finishInteractionDefensively's catch, replace the 400 branch:if(isSessionMissing){// mirror the deleted-account guard at src/idp/provider.js:268,407,420expireSessionCookies(reply,request);// The authorization URL is reachable via interaction.returnTo —// but the helper doesn't currently receive the interaction object.// Either pass it as a new arg, or accept a `retryUrl` arg from each caller.reply.raw.writeHead(303,{Location: retryUrl});reply.raw.end();return;}
Adding help wanted + priority: low to signal this is a well-scoped contributor task rather than an urgent fix — after #540 the user sees a clear error page instead of a hang, so the remaining work is UX polish.
Activity
melvincarvalho commentedon Jun 8, 2026
Partial overlap with #412 / PR #539
PR #539 (closes #412) lands a partial of the fix proposed here — scoped to
handleSchnorrCompleteonly, and using the simpler Approach C (return a 4xx error page) rather than the auto-healing 303-redirect-and-restart shape this issue proposes.handleSchnorrComplete(line 823)reply.rawon SessionNotFoundexpireSessionCookies+ 303 to the authorization URLhandleLoginbrowser branch (165)handleConsent(289)handlePasskeyComplete(606)handlePasskeySkip(644)So once #539 merges:
schnorr-completeis gone (turns into a 400 with a "restart login" page).This issue stays load-bearing for the remaining work. The mechanical shape is the same across all five — could be a single helper, e.g.
await finishOrExpireAndRetry(reply, request, provider, returnTo, ...), with the four sites consolidating onto it.(Almost filed a separate "sweep" issue when working on #412; the dupe search caught this one — leaving the cross-reference here so the relationship is documented.)
refactor(idp): sweep hijack-then-throw defensive pattern across all 5…
melvincarvalho commentedon Jun 8, 2026
Update: foundation landed across all 5 sites in #540
PR #540 (squash-merged as
9051737) extracted the defensive recovery pattern into a single helperfinishInteractionDefensivelyand replaced all fivereply.hijack(); return provider.interactionFinished(...)sites insrc/idp/interactions.jswith calls to it.So the previous status comment is now stale — every interaction handler is now hang-proof on
SessionNotFound:handleSchnorrCompletehandleLogin(browser branch)handleConsent(the "Allow access" path this issue originally describes)handlePasskeyCompletehandlePasskeySkipWhat this issue still owns
The UX upgrade from "show a 400 error page" → "self-heal via
expireSessionCookies+ 303 to the authorization URL". The helper is now the single place to add that logic — once this issue gets the work,finishInteractionDefensivelygrows an extra branch (or the SessionNotFound branch swapserrorPagefor anexpireSessionCookies(reply, request); reply.raw.writeHead(303, { Location: <authUrl> })), and all five handlers inherit it for free.Sketch for whoever picks this up
Adding
help wanted+priority: lowto signal this is a well-scoped contributor task rather than an urgent fix — after #540 the user sees a clear error page instead of a hang, so the remaining work is UX polish.bump version to 0.0.206