Skip to content

OIDC rejects every valid token: decodeJWT returns crow::json::rvalue pointing into freed strings #273

Done

Description

@jrosskopf

Impact: with auth.type: oidc (REST, and MCP, which uses the same handler), every token gets 401 in v26.11.25, including correct ones. OIDC authentication does not work.

Cause: OIDCAuthHandler::decodeJWT (src/oidc_auth_handler.cpp around 255-285) base64-decodes the header and payload into the local strings header_json and payload_json, parses them with crow::json::load, and returns std::make_pair(header, payload). A crow::json::rvalue refers into the buffer it was parsed from, which is freed when the function returns. The later header.has("alg") / has("kid") calls read freed memory. The log shows OIDC error: JWT header missing 'alg' field (or 'kid' when kid is the first key).

Repro (found while writing the authentication guide, #272):

  1. Run a mock issuer on 127.0.0.1 that serves discovery and JWKS.
  2. Configure auth: {enabled: true, type: oidc, oidc: {issuer-url: http://127.0.0.1:<port>, client-id: x}}.
  3. Send an RS256 token with the header {"alg":"RS256","typ":"JWT","kid":"k1"} and valid claims.
  4. The response is 401. There is no end-to-end OIDC success test in the suite, which is why this went unnoticed.

Fix direction: keep the JSON text alive alongside the parsed values (return the strings together with the rvalues, or parse into an owning crow::json::wvalue / use jwt-cpp's decoded claims). Add an integration test against a mock IdP that accepts a valid token and rejects bad signature, issuer, audience and expiry.

Related findings from the same review:

  • A dotted roles-claim always means nesting, so Auth0-style namespaced claims (https://app.example.com/roles) can't resolve.
  • An explicit username-claim: sub is overridden by the presets.
  • groups-claim, scopes, client-secret, enable-client-credentials and enable-refresh-tokens are parsed but have no effect.
  • Without allowed-audiences, client-id is not checked against aud.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions