Skip to content

fix(auth)!: trust only configured issuers #275

Closed

Description

@uniqueg

Problem

validate_token (foca/security/auth.py) decodes the token without verifying it, then builds the OIDC discovery URL from the token's own iss claim. There is no issuer allowlist (AuthConfig has only claim_issuer), the discovery document's issuer is not compared to iss, and jwt.decode gets no issuer=. As a result, a token minted by any OIDC provider can pass validation, and an unauthenticated client can make the service send requests to URLs it chooses (SSRF; redirects are followed; userinfo also forwards the bearer token).
In addition:

  • With validation_checks: any (shipped in templates/config.yaml), a 2xx from the userinfo endpoint is enough; the signature, exp and aud checks never run. The userinfo sub is not compared.
  • The returned claims come from the unverified decode. _validate_jwt_public_key discards its verified claims, so add_key_to_claims has no effect.
  • audience: null (default) disables aud checks silently; allow_expired disables exp silently.
  • requests.get without timeout, and discovery plus JWKS are fetched on every request with no caching (also blocks the event loop under Connexion 3, C3 2.4).
  • Wrong or broken messages: missing issuer claim reported as missing identity claim; missing quote; missing f prefix; verify=True is ignored by PyJWT 2.

Proposal

  • Add security.auth.issuers: list[str] (exact string match). Reject a token whose iss is not listed before any network call. With an empty list, reject every token (fail closed) and log an error at startup.
  • Compare the discovery document's issuer to iss; pass issuer= to jwt.decode; only https URLs (loopback http allowed for tests); no redirects; timeouts (security.auth.timeout, default e.g. 5 s).
  • Always verify the signature locally. Replace validation_methods/validation_checks with validate_userinfo: bool = False, an additional check whose sub must equal the token's sub.
  • Decode with options={"require": ["exp", "iat", "iss", "sub"]}; return the verified claims (with public_key if add_key_to_claims).
  • Warn at startup if audience is unset or allow_expired is true.
  • Cache discovery documents and JWKS per trusted issuer with a TTL; refetch the JWKS once on unknown kid, rate-limited (e.g. jwt.PyJWKClient, if redirects/timeouts can be controlled; otherwise a small cached fetcher).
  • Split a pure validate_jwt(token, conf: AuthConfig) -> dict from the Connexion-facing validate_token, so the Connexion 3 migration can reuse it.
  • Log rejections at INFO with reason class and iss (never the token). Fix the messages listed above.

Acceptance criteria

  • Token with an unlisted iss is rejected with 401 and no outbound request is made (test asserts no HTTP call).
  • Discovery issuer mismatch, bad signature, wrong aud, expired, and missing exp/iat/iss/sub are each rejected (tests).
  • Userinfo check cannot replace local verification; mismatching userinfo sub is rejected (test).
  • token_info["claims"] contains the verified claims, incl. public_key when enabled (test).
  • Repeated requests reuse cached discovery/JWKS; all fetches have timeouts and do not follow redirects (tests).
  • Startup warnings for empty issuers, unset audience, allow_expired: true (tests).
  • AuthConfig, templates/config.yaml, README and docs/access_control/README.md updated; migration note written.

Breaking changes

proTES and cloud-registry must set security.auth.issuers (e.g. LS Login issuer URL) and should set audience; remove validation_methods/validation_checks and use validate_userinfo if needed. Tokens must be JWTs verifiable with the issuer's JWKS. cloud-registry uses its own x-bearerInfoFunc: app.validate_token; check whether it should switch to FOCA's.

Related

Sec #1, #2, #3; Simp #6 (auth parts); C3 2.4; #188

Activity

  1. added
    priority: critical
    type flag: breaking change
    type: auth
    type: bug
    type: security
    workload: days
    on Oct 18, 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

    priority: criticaltype flag: breaking changetype: authtype: bugtype: securityworkload: days

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions