Repository navigation
Description
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 intemplates/config.yaml), a 2xx from the userinfo endpoint is enough; the signature,expandaudchecks never run. The userinfosubis not compared. - The returned claims come from the unverified decode.
_validate_jwt_public_keydiscards its verified claims, soadd_key_to_claimshas no effect. audience: null(default) disablesaudchecks silently;allow_expireddisablesexpsilently.requests.getwithout 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
fprefix;verify=Trueis ignored by PyJWT 2.
Proposal
- Add
security.auth.issuers: list[str](exact string match). Reject a token whoseissis 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
issuertoiss; passissuer=tojwt.decode; onlyhttpsURLs (loopbackhttpallowed for tests); no redirects; timeouts (security.auth.timeout, default e.g. 5 s). - Always verify the signature locally. Replace
validation_methods/validation_checkswithvalidate_userinfo: bool = False, an additional check whosesubmust equal the token'ssub. - Decode with
options={"require": ["exp", "iat", "iss", "sub"]}; return the verified claims (withpublic_keyifadd_key_to_claims). - Warn at startup if
audienceis unset orallow_expiredis 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) -> dictfrom the Connexion-facingvalidate_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
issis rejected with 401 and no outbound request is made (test asserts no HTTP call). - Discovery
issuermismatch, bad signature, wrongaud, expired, and missingexp/iat/iss/subare each rejected (tests). - Userinfo check cannot replace local verification; mismatching userinfo
subis rejected (test). -
token_info["claims"]contains the verified claims, incl.public_keywhen enabled (test). - Repeated requests reuse cached discovery/JWKS; all fetches have timeouts and do not follow redirects (tests).
- Startup warnings for empty
issuers, unsetaudience,allow_expired: true(tests). -
AuthConfig,templates/config.yaml, README anddocs/access_control/README.mdupdated; 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.
Activity