Repository navigation
Description
Bug description
When a private_key_jwt client fails authentication at the token endpoint, the embedded authorization server often does not answer 401 invalid_client. RFC 6749 section 5.2 says a failed client authentication is invalid_client, so a client cannot tell what went wrong.
Reported by Chris Burns while reviewing #6953, who saw:
- an
iatslightly in the future, an expired assertion, or a lifetime over 5 minutes returns HTTP 500 with"error":"error"; - an unknown
kidreturns HTTP 400invalid_request.
I traced the causes in the code (fosite v0.49.0 and ToolHive's storage). I did not reproduce them with a test.
Steps to reproduce
Authenticate a private_key_jwt client at /oauth/token with an assertion that:
- has an
iatorexpthat fails claim validation (futureiat, pastexp), or - has an
expmore than 5 minutes ahead, or - carries a
kidthat is not in the client's JWKS.
This applies to any private_key_jwt client, DCR-registered or configured.
Expected behavior
401 invalid_client with a hint that says why (assertion expired, not yet valid, lifetime too long, unknown key id). A key that is not registered yet, for example during a key rotation, should read as a client configuration fault, not as a problem with the user's access token.
Actual behavior
- Claim validation failures (future
iat, pastexp). Inclient_authentication.gofosite returns the raw inner error (return nil, e.Inner, lines 137 to 141). It is not an RFC 6749 error, andErrorToRFC6749Error(errors.go:279) turns an unrecognised error into HTTP 500 with the error nameerror. - Lifetime over 5 minutes. fosite calls
SetClientAssertionJWTand returns its error unchanged (lines 179 to 181). ToolHive's storage returns a plainfmt.Errorf("assertion lifetime exceeds maximum of ...")in both backends (pkg/authserver/storage/memory.go:978,redis.go:978), so this is also a 500. This one is ToolHive's own code. - Unknown
kid. fosite'sfindPublicKeyreturnsErrInvalidRequest(lines 280, 299, 301), which is 400invalid_request.
Additional context
- ToolHive already wraps fosite's client authentication for SPIFFE (
pkg/authserver/server/provider.go:629, throughClientAuthenticationStrategy), so there is a place to map errors. - Authorization server: allow clock skew on private_key_jwt client assertions #6954 (clock skew on
private_key_jwtclient assertions) is in the same code path. A futureiatis one of the cases that returns 500 today. If skew tolerance is added, the error for the cases outside the tolerance should still beinvalid_client. It is worth doing the two together, or in order. - Part of the broker work in Stable pre-provisioned broker client for token exchange and ID-JAG redemption #6893.
Proposed fix
- In both storage backends, return
fosite.ErrInvalidClientwith a hint fromSetClientAssertionJWTwhen the lifetime is too long. - In the client authentication wrapper, for requests that carry a
client_assertion: map non-RFC 6749 errors from claim validation toinvalid_client, and map "unknown kid" and "no matching key" toinvalid_client. Leave genuine storage failures as 500. - Keep the specific reason in the error hint, and never include assertion or key material in it.
Acceptance criteria
- A future
iat, an expired assertion, a lifetime over 5 minutes, and an unknownkideach return 401invalid_clientwith a hint that names the cause. - A real storage failure still returns 500.
- Tests cover each case for a DCR client and a configured client, on the memory and Redis backends.
Activity
pcbeingused333 commentedon Nov 1, 2026
I'd like to work on this.
I have a fix ready that maps these private_key_jwt assertion failures (future
iat, expiredexp, lifetime over the limit, unknownkid) to401 invalid_clientper RFC 6749 §5.2, with tests for each case inpkg/authserver/serverandpkg/authserver/storage. Happy to open the PR once assigned.jhrozek commentedon Nov 3, 2026
Closing as a duplicate of "Authorization server: refuse every failed private_key_jwt client assertion with 401 invalid_client" (#7028). It covers the same errors and is linked under the epic "Authorization server: refresh tokens and ID-JAG issuance for delegated agents" (#6886). The two cases only this issue lists, an unknown
kidand aniatslightly in the future, are copied to #7028.jhrozek commentedon Nov 3, 2026
@pcbeingused333 thank you, I will assign you the issue that turned out to be a duplicate instead.