Skip to content

OIDC login failure reflects raw openid-client error messages into the /?error= redirect (info disclosure + attacker-influenced UI text) #422

Closed

Description

@aniruddhaadak80

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:

  1. 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).
  2. 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/login visit) controls up to URL-length-bounded text rendered by whatever displays the error query param on /. That's phishing-friendly content served from your origin.
  3. Inconsistent UX: some failures get curated reasons, others get stack-adjacent noise.

Steps to reproduce

  1. Enable OIDC; open GET /api/v1/auth/login?return_to=/ to seed the oauth_state cookie.
  2. Hand-craft a callback whose code will fail verification but whose state matches the cookie: GET /api/v1/auth/callback?code=invalid&state=<cookie state>.
  3. Observe the redirect /?error=... containing the verbatim openid-client exception 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

  1. added a commit that references this issue on Sep 28, 2026
    a638cfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions