Repository navigation
Description
What happened?
The OIDC callback handler deliberately sanitizes IdP-provided errors, but then reflects the raw exception message from the token-exchange code path straight into a user-facing redirect:
// packages/trueforge/src/apis/auth.ts (main @ 506bf5c, oAuthCallbackRoute)
} catch (error) {
params.logger.error('Failed to exchange authorization code', extractErrorLogFields(error));
if (await resolveAuthUser(c)) {
return c.redirect(safeReturnTo(pending.return_to), 302);
}
const reason = error instanceof Error ? error.message : 'login_failed';
return c.redirect(oauthErrorRedirect(reason), 302); // <- raw error.message to the browser
}Compare with the care taken ten lines earlier for the IdP error branch:
// Only reflect a non-empty IdP `error_description` when the IdP returned an error.
// No fallback to the `error` code — blank/missing descriptions use the default.
// Our own validation failures (state mismatch / missing code) stay generic too.
const description = query.error_description?.trim();
const reason = query.error && description ? description : 'login_failed';The exchange path throws from openid-client internals (authorizationCodeGrant) — those errors embed upstream HTTP/response details (token-endpoint error bodies, issuer URLs, discovery/JWKS fetch failures). Consequences:
- Information disclosure: internal endpoints/issuer hostnames and upstream error payloads surface in
/?error=<message>, visible in browser history, screenshots, and support tickets. The project already treats this class of detail as log-worthy only (params.logger.error). - Unbounded attacker-influenced UI text on a trusted origin: an attacker who induces a failing exchange (e.g. replaying/hand-crafting a callback that passes the state check but fails PKCE — the state cookie is set by any unauthenticated
/api/v1/auth/loginvisit) controls up to URL-length-bounded text rendered by whatever displays theerrorquery param on/. That's phishing-friendly content served from your origin. - Inconsistent UX: some failures get curated reasons, others get stack-adjacent noise.
Steps to reproduce
- Enable OIDC; open
GET /api/v1/auth/login?return_to=/to seed theoauth_statecookie. - Hand-craft a callback whose
codewill fail verification but whosestatematches the cookie:GET /api/v1/auth/callback?code=invalid&state=<cookie state>. - Observe the redirect
/?error=...containing the verbatimopenid-clientexception text (e.g. token request failure details including endpoint/host information).
Expected behavior
Map exchange failures to the same small set of generic reasons used elsewhere ('login_failed', maybe 'session_expired'), keep full detail in server logs via extractErrorLogFields, and never interpolate raw error.message into redirects.
How are you running TrueForge?
npx (standalone / SQLite)
Version
main @ 506bf5c
Environment
OS: any
Node.js version: 22.14+
Browser (if UI-related): any
Activity
fix(trueforge): keep OIDC exchange failures out of the error redirect (…