Skip to content

OIDC IdP 500s on Node <20: @koa/router (via oidc-provider) uses Array#toReversed #523

Open

Description

@melvincarvalho

Summary

Signing in via the built-in IdP throws a 500 on Node runtimes older than v20:

TypeError: matchedLayers.toReversed is not a function
    at .../javascript-solid-server/src/idp/index.js:146  (forwardToProvider -> provider.callback())
    at .../@koa/router/dist/index.js:1042
POST /idp/reg -> 500

The call is not in JSS source — it's in @koa/[email protected] (dist/index.js:1042), which oidc-provider uses internally for route matching:

const routeLayer = matchedLayers.toReversed().find((layer) => layer.methods.length > 0);

Array.prototype.toReversed is ES2023 (Node 20+). On Node 18 — e.g. nodejs-mobile's embedded runtime — it's undefined, so OIDC dynamic client registration / the interaction flow 500s and sign-in bounces back.

Repro

Embed JSS with idp: true on a Node 18 runtime (here: nodejs-mobile on Android, JSS 0.0.196). Open a Solid client (pilot), point it at the pod, sign in → POST /idp/reg → 500.

Why it matters

Same class as the other oidc-provider-driven runtime gaps tracked in #522 (Intl.ListFormat, global crypto, URL.parse) — modern-Node features the IdP dependency chain assumes. oidc-provider already warns "Use Node.js v22.x LTS".

Options

  1. Document a minimum runtime for the IdP (Node 20+, ideally 22 LTS per oidc-provider's own warning).
  2. Ship a small polyfill for the change-array-by-copy methods when idp is enabled, so embedded/older runtimes work. (We currently polyfill toReversed / toSorted / with app-side as a workaround.)
  3. Bump/replace the dependency if a Node-18-compatible @koa/router line exists (probably not worth it).

Not a one-line JSS source fix like #520 / #521 — filing for tracking because JSS ships and enables the IdP.

Activity

  1. added
    bug
    on May 23, 2026
  2. melvincarvalho commented on May 23, 2026

    @melvincarvalho
    ContributorAuthor

    Surfaced by the Android (nodejs-mobile) work — tracked in #522. Dependency-driven (oidc-provider → @koa/router), so it belongs with the runtime-contract items rather than the source-level fixes #520 / #521.

  3. melvincarvalho commented on May 23, 2026

    @melvincarvalho
    ContributorAuthor

    A second instance of the same root cause turned up right after toReversed: oidc-provider also calls crypto.hash() (the one-shot helper added in Node 21.7) in ~8 files (lib/models/client.js, lib/helpers/pkce.js, certificate_thumbprint.js, validate_dpop.js, replay_detection.js, initialize_keystore.js, id_token.js, script_src_sha.js). On Node 18 this 500s the /idp/auth interaction with a generic server_error.

    Notable: it's imported via import * as crypto from 'node:crypto' — an immutable namespace, so a runtime polyfill can't add hash; the call sites have to be rewritten (createHash + digest) or the runtime bumped.

    Reinforces option 1 (document Node 20+/22 LTS as the IdP's minimum runtime) — the polyfill route needs a growing per-API shim list (toReversed, crypto.hash, URL.parse, Intl.ListFormat, global crypto, …), all because oidc-provider targets current LTS.

    With both rewritten downstream, the OIDC flow now reaches the login interaction page (200) on nodejs-mobile's Node 18.

  4. melvincarvalho commented on Jun 9, 2026

    @melvincarvalho
    ContributorAuthor

    Disposition (2026-06-08): deferring

    After reviewing the options against the current landscape, doing nothing is the right call for now:

    • Node 18 reached EOL April 2025 — the affected user base is naturally shrinking.
    • nodejs-mobile users already have a working path — per comment 2, "with both rewritten downstream, the OIDC flow now reaches the login interaction page (200) on nodejs-mobile's Node 18." The Android target has a downstream patch story.
    • Polyfilling is a dead end — crypto.hash lives in an immutable node:crypto namespace; even fixing toReversed wouldn't unblock the auth flow.
    • Bumping the dep chain isn't worth it — the issue itself flagged this.

    Net: the problem is decaying without our action, and any code we add now (polyfills, conditional shims, runtime warnings) becomes maintenance debt the moment Node 18 fully fades.

    Tracking the eventual engines.node bump separately as a follow-up — that's the disposition the issue itself preferred (Option 1). This issue stays open as the record of why and when Node 18 stopped being viable, in case a new user hits it before the engines bump lands.

  5. added 2 commits that reference this issue on Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions