Repository navigation
Description
Symptom
GET /idp/interaction/<uid>/schnorr-complete?accountId=<id> hangs and the gateway times out with 504. JSS log shows:
```
Schnorr login completed (accountId=b0b1707f-... uid=_T_qlTgrG3zS1...)
Promise errored, but reply.sent = true was set
err: SessionNotFound: invalid_request — interaction session id cookie not found
at #getInteraction (oidc-provider/lib/provider.js:405)
at Provider.interactionResult (provider.js:199)
at Provider.interactionFinished (provider.js:217)
at handleSchnorrComplete (src/idp/interactions.js:833)
```
The connection hangs because the handler called `reply.hijack()` before `provider.interactionFinished(...)`, so when `interactionFinished` throws, Fastify can't send the error and the socket sits open until the gateway times it out.
Reproduction
Anything that breaks `_interaction` cookie continuity between the OIDC `/auth` step and `/schnorr-complete`:
- Start the OIDC flow in browser A, copy-paste the interaction URL into browser B (today's repro)
- Third-party cookie blocking on a cross-site IdP/RP boundary
- Incognito → main session
- The same flow after a long idle (cookie expired but interaction record still findable)
Cause
`handleSchnorrComplete` (`src/idp/interactions.js:805`) does the right thing structurally — looks up the interaction by `uid`, validates the accountId — and then calls `provider.interactionFinished(request.raw, reply.raw, interaction.result, ...)`. `interactionFinished` internally re-reads the `_interaction` cookie via `#getInteraction` and explodes when it's missing, even though we already proved we have the right interaction.
Two compounding issues:
- Unnecessary cookie dependency. We have the interaction object in hand. The cookie check is redundant for this code path.
- Hijack-then-throw silently hangs. `reply.hijack()` is called BEFORE `interactionFinished`. If `interactionFinished` throws, Fastify's `Promise errored, but reply.sent = true was set` warning fires and nobody writes a response. Connection hangs → 504.
Fix sketches
A. Move the OIDC finalize into `handleSchnorrLogin`. The login handler already saves `interaction.result` and has the `_interaction` cookie in flight (it's still the same browser, same request). After saving, it can call `provider.interactionFinished(request.raw, reply.raw, result, {...})` and return its redirect target as `redirectUrl` in the JSON. Drop `schnorr-complete` entirely. This is the cleanest fix because it removes the cookie-dependency window.
B. Keep `schnorr-complete` but bypass `interactionFinished`. We have the saved `interaction.result` and can directly construct the OIDC continue URL (`interaction.returnTo`) ourselves. Redirect the browser there and oidc-provider's auth endpoint picks up the saved result without needing the cookie.
C. Defensive: don't `reply.hijack()` until AFTER `interactionFinished` resolves. At minimum this turns a 504 hang into a clean 4xx so users get a real error.
A or B fix the actual flow. C should land regardless.
Refs
- Surfaced during live testing of auth: serve /.well-known/did/nostr/<pubkey>.json (#407) #408 on solid.social
- Handler: `src/idp/interactions.js:805-838`
- Related auth: NIP-98 verifier upgrades did:nostr → WebID via verificationMethod lookup (#4 Phase 2A via CID) #399 / idp: "Sign in with Schnorr" resolves user via typed username + CID verificationMethod #403 / idp: "Sign in with Schnorr" resolves user via typed username + VM (#403) #405 (the Schnorr login chain)
Activity
melvincarvalho commentedon Jun 8, 2026
Same anti-pattern in 4 other handlers in
src/idp/interactions.jsWhile preparing #539 (Approach C for this issue, scoped to
handleSchnorrComplete), I confirmed the samereply.hijack()→provider.interactionFinished(...)→ outer-catch-can't-respond shape exists at four other sites. All four have identical risk: ifinteractionFinishedthrows (most commonlySessionNotFoundfrom a missing_interactioncookie), the outercatch { reply.code(500).type('text/html').send(...) }is a no-op against a hijacked reply, and the connection hangs to a gateway 504 — exactly the symptom this issue describes.handleLogin(browser branch)/idp/interaction/<uid>/loginfrom a browser formhandleConsent/idp/interaction/<uid>/confirmhandlePasskeyComplete/idp/interaction/<uid>/passkey-completeafter WebAuthn ceremonyhandlePasskeySkip/idp/interaction/<uid>/passkey-skipAll four have the same outer
try { … reply.hijack(); return provider.interactionFinished(...) } catch (err) { return reply.code(500)…send(errorPage(...)) }shape — the outer catch is structurally unable to recover after hijack.#539 deliberately stays narrow (issue scope = schnorr only). If a broader sweep is wanted, the fix is mechanical: each of the four gets the same
try { await interactionFinished(...) } catch (err) { if (reply.raw.headersSent) throw err; reply.raw.writeHead(...); reply.raw.end(errorPage(...)) }wrapper. A small helper — e.g.await finishInteractionOrRecover(reply, request, provider, request.raw, reply.raw, result, opts)— would let all five sites collapse onto one call site and eliminate the anti-pattern entirely.Happy to file that as a follow-up issue ("sweep hijack-then-throw across all 5 interaction handlers"), or fold it into a separate PR if the scope feels right here.
melvincarvalho commentedon Jun 8, 2026
Cross-reference: #526 is already the broader sweep
Followed up on my "happy to file that as a follow-up issue" line in the previous comment — turns out #526 already covers the broader sweep. It explicitly lists the same five
interactionFinishedcall sites (lines ~166, 289, 606, 644, 823) and proposes a stronger fix than what #539 lands here:So the layering is:
handleSchnorrCompleteonlyNot duplicates — layered. #539 is the safety net (no more 504 anywhere); #526 is the UX win (no user-visible error at all). Once #539 merges and closes this issue, the remaining work lives in #526.
fix(idp): handleSchnorrComplete recovers from interactionFinished thr…
bump version to 0.0.206