Repository navigation
Description
Bug description
When an embedded auth server uses Dynamic Client Registration (DCR) against an upstream that is itself a ToolHive auth server, the downstream keeps its cached registration forever, while the upstream deletes it after 30 days without a token exchange. After that, every authorization the downstream starts is rejected by the upstream with invalid_client, and nothing recovers on its own.
The two sides disagree about the registration's lifetime:
- Upstream (server side). DCR-issued clients are stored with
DefaultDCRClientTTL(30 days,pkg/authserver/storage/config.go). The TTL is renewed only by a successful token exchange or refresh (RenewClientTTLinpkg/authserver/server/handlers/token.go). The registration response still advertisesclient_secret_expires_at: 0("does not expire",pkg/authserver/server/handlers/dcr.go), which is deliberate. - Downstream (client side).
pkg/auth/dcrpersists the resolution and, on a cache hit, returns it without any network I/O. The only invalidation signal isclient_secret_expires_at(lookupCachedResolution), which is0here. The 90-daydcrStaleAgeThresholdonly logs a warning.
So an idle registration is evicted upstream but kept downstream. The same happens if the upstream loses its client storage for any other reason (for example, a Redis/Valkey wipe or a restore).
The browser is the only party that sees the error: /oauth/authorize on the upstream renders it directly. The downstream never sees it, so it can't react, and it presents the same dead client_id on every attempt. The only workaround today is to delete the cached DCR row from the downstream's storage by hand and restart.
Steps to reproduce
- Run auth server A (the upstream) with Redis storage and DCR enabled.
- Run embedded auth server B (the downstream) with Redis storage and an OAuth2 upstream pointing at A through
dcr_config(discovery_url). On boot, B registers on A and caches the client. - Start an authorization through B: A accepts the client and shows its consent page.
- Let A's Redis advance past
DefaultDCRClientTTLwithout any token exchange for that client (or delete the client from A's storage). - Restart B against the same Redis and start a new authorization through B.
A self-contained integration test reproduces this with two in-process auth servers and miniredis (FastForward past the TTL). It will be included in the fix PR.
Expected behavior
After the upstream has dropped the registration, the downstream detects it and registers a new client. Authorizations work again without manual intervention.
Actual behavior
B reuses the cached client_id and redirects the browser to A, which answers:
{"error":"invalid_client","error_description":"Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method). The requested OAuth 2.0 Client does not exist."}This repeats on every attempt and survives restarts of B.
Environment (if relevant)
- ToolHive version:
mainat 5220a0a (also present in v0.50.0 – v0.53.0)
Additional context
Proposed fix, client side in pkg/auth/dcr:
- Validate on cache hit. On a cache hit, send one token-endpoint request with the cached client credentials and a deliberately invalid authorization code. Token endpoints authenticate the client before they validate the grant (RFC 6749 §5.2; fosite's
NewAccessRequestdoes this too), so:invalid_clientmeans the registration is gone;invalid_grantmeans the registration is alive;- anything else (5xx, network error, a non-OAuth error) is inconclusive, and the cached registration is kept so boot is never blocked.
- Replace the stale row. On
invalid_client, re-register and replace the stale row withUpdateDCRCredentialsIfUnchanged(Add compare-and-set update for DCR credentials #6758), so concurrent replicas converge on one registration.
Limitation: the resolver runs only when the auth server is constructed, so this recovers at the next restart, not while the process is running.
Activity
aron-muon commentedon Oct 14, 2026
We hit this in production with a third-party upstream rather than a second
ToolHive auth server, and it adds two data points to the report.
Field evidence. Two
MCPRemoteProxydeployments (staging and productionclusters, separate Redis stores) register with the same vendor authorization
server through
dcrConfig.registrationEndpoint. The vendor issues publicclients only (
token_endpoint_auth_methods_supported: ["none"]), so everyregistration response carries
client_secret_expires_at: 0and the onlyinvalidation rule in
lookupCachedResolutionnever fires. The vendor purgedits registered-client store twice in three weeks (once before Sept 24, once
between Oct 7 and Oct 12). Each time, every proxy start logged
dcr: cache hitwith the deadclient_id(dcr_age_days49 and 12respectively) and the browser got the vendor's unknown-client error on
/authorize; the proxies never saw it. Recovery was the manual path the issuedescribes: delete the
dcr:row in Redis and restart the pods. The ages atdeath (about 30 days and under 12 days) show this was not a TTL on the
vendor's side but a wipe, so no client-side age heuristic alone would have
predicted it.
The token-endpoint probe is a false negative for this vendor. Its token
endpoint validates the grant before the client: redeeming a bogus code with the
purged
client_id, with the live one, and with a made-up one all return400 {"error": "invalid_grant", "error_description": "Invalid authorization code"}.#6822 would read that as "registration alive" and keep the dead row. With
token_endpoint_auth_method: nonethere is nothing for the endpoint toauthenticate, so this is probably common among public-client-only upstreams.
Here only the authorization endpoint tells the two apart (302 to the vendor's
login for a known client, a 400
invalid_requestabout the redirect URI for anunknown one), and that text is vendor-specific.
A complementary operator-driven knob. Two situations still need a
deliberate rotation with no Redis surgery:
asked us to re-register, migration between vendor tenants).
PR #6825 adds
dcrConfig.rotationKey, an optional operator-chosen label thatis folded into the DCR cache key (
DCRKey,redisDCRKey, the memory map keyand the singleflight key) only when non-empty. Bumping it in the
MCPExternalAuthConfigmakes the next start register a fresh client; theprevious row is left in place, and existing keys and rows are untouched when
the field is empty. It does not change the resolve-once-at-startup model
(#6496) and stays out of the probe's way: both can land independently.
Possible follow-up for the fix PR. A
dcrConfig.maxRegistrationAgeduration that treats a cached row older than the limit as stale (re-register
at startup, replace with
UpdateDCRCredentialsIfUnchangedso replicasconverge) would give time-based rotation for upstreams where the probe cannot
tell. We did not include it here to avoid colliding with the probe work in
lookupCachedResolution; happy to add it on top of the fix PR if wanted.One caveat worth stating in docs for either mechanism: on providers that bind
refresh tokens to the client (#6508), a new client generation stops refreshing
the old upstream tokens, so affected users sign in again once.
Add rotationKey for upstream DCR re-registration
peppescg commentedon Oct 14, 2026
@aron-muon thanks for the field report, it's really useful, and it shows the problem isn't limited to two ToolHive auth servers talking to each other.
You're right about the probe. It only decides anything when the upstream authenticates the client before it checks the grant. ToolHive's own auth server (fosite) does that for both public and confidential clients, so that case is covered. With an upstream that returns
invalid_grantfor any client_id, the probe simply can't tell the difference, and the behavior stays exactly as it is today. I've updated the description and the code comments in #6822 to say this explicitly.I see #6825 as a good complement and I'm in favour of it, since a deliberate way for operators to rotate the registration is useful even where the probe works. Two small notes on it. The
RotationKeydoc comment says the rejection "is only visible in the user's browser, so the resolver cannot detect it", which won't hold for every upstream once #6822 is merged, so something like "may not be able to detect it" would age better. The two PRs also conflict in one place, thedcrStaleAgeThresholdcomment instore.go, so whichever lands second just needs to merge the two sentences.About
maxRegistrationAge, I have a few doubts and I'd like to check them with you, since you've run this in production. You mentioned that with #6508 users sign in again once after a new client generation. With a rotation key that happens once, when the operator decides, but with a time threshold wouldn't it happen at every rotation, even when the client is still valid? With more than one replica, wouldn't the first one that restarts after the threshold switch to a new client while the others keep the old one (#6496), so a login could start on one generation and end on the other? How many replicas do your proxies run? Wouldn't each rotation also leave the old registration behind on the vendor side, and does your vendor clean those up or would they pile up? And since you noted that no age heuristic would have predicted the wipes you saw, what would the threshold mainly cover in your case, periodic rotation for its own sake?Longer term, Client ID Metadata Documents could be an option, in case your vendor supports them. With CIMD there's no stored registration on the upstream side, so nothing that can be wiped or evicted, and the MCP spec is now deprecating DCR in favour of CIMD anyway.
Add dcrConfig.rotationKey to re-register upstream DCR clients (#6825)
Re-register DCR clients the upstream evicted
aron-muon commentedon Oct 15, 2026
Thanks, and agreed on both notes for #6825: "may not be able to detect it" is the better wording, and since #6825 landed first the
dcrStaleAgeThresholdcomment merge falls to #6822; I'll fix the doc wording in the follow-up below.Your questions, from our deployment:
registration_access_token, so RFC 7592 DELETE is not available for cleanup. On other vendors orphans would accumulate.maxRegistrationAge: you are right, it would mostly buy periodic rotation for its own sake and would not have predicted either wipe. Dropping it.What would have caught our case is a check against the authorization endpoint, which I'd like to add as an opt-in second strategy in #6822's framework. RFC 6749 §4.1.2.1: for an unknown client_id or a redirect_uri mismatch the AS MUST NOT redirect and informs the user directly; a known client gets a redirect to login/consent (or to the redirect_uri with an error). Our vendor behaves exactly like that: 302 to its IdP for the live client, direct 400
invalid_requestfor a purged or made-up one. Classification: 2xx or 3xx = alive; direct 4xx other than 429 = registration not accepted, re-register; 5xx, 429, network errors = inconclusive, keep the cached client. Opt-in per upstream (dcrConfig.registrationProbe: tokenEndpoint | authorizationEndpoint, defaulttokenEndpoint= #6822's behaviour), because some servers answer direct 4xx on the authorization endpoint for unrelated reasons. I'll open it stacked on #6822 once that merges, together with the doc wording fix.On CIMD: agreed as the end state. Our vendor does not advertise
client_id_metadata_document_supportedyet, and the embedded auth server's upstream path would also need to present a CIMD client_id; happy to look at that once a vendor supports it.Re-register DCR clients the upstream evicted (#6822)
aron-muon commentedon Oct 15, 2026
The authorization-endpoint probe is up as #6834 (
dcrConfig.registrationProbe: tokenEndpoint | authorizationEndpoint | none, default unchanged), rebased on #6822 and carrying therotationKeywording fix.