Skip to content

fix(federation): refuse a chain that expires while it resolves, and answer a re-entrant failure hook - #990

Merged
osanderson merged 3 commits into
mainfrom
fix/audit-e6-e7
Nov 25, 2026
Merged

osanderson merged 3 commits into
mainfrom
fix/audit-e6-e7

Conversation

@osanderson

Copy link
Copy Markdown
Collaborator

This PR fixes two federation issues from the audit's unverified hypotheses (section E). Both were confirmed on v0.85.0.

E-6: a trust chain that expires while it resolves (fix(federation))

Resolver.Resolve read the clock once at the start and checked every statement against that time. If a slow fetch took the clock past the chain's exp, Resolve returned a chain that had already expired.

AutomaticClientRepository then registered and cached the client, capped at the chain's exp, so it wasn't kept beyond the expiry. The requests sharing that one resolution were still answered with the expired registration: ResolveClient returned the client, and the key source returned its keys.

The fix checks the chain's ExpiresAt against the clock at two points:

  • When Resolve finishes. checkChainUnexpired uses the same MaxClockSkew tolerance as each statement's exp check. A chain accepted today, when no time passes during resolution, is still accepted.
  • Again in register. Fetching the RP's jwks_uri can take the chain past its expiry after Resolve returns. A chain refused here fails like any other registration: invalid_client, reported to the hook and remembered.

UPGRADING.md has a section under v0.85.1. The only new refusal is a chain that expires part-way through a resolution.

E-7: a resolution-failure hook resolving its own client_id (fix(federation))

R-20's follow-up remembers a failure before OnResolutionFailure runs, so a re-entrant ResolveClient normally gets that failure at once. It wasn't remembered in two cases:

  • The failure memory was full. It holds 4096 entries, and any unauthenticated caller can fill it in well under a second.
  • The hook ran longer than FailureCacheAge.

In either case, a hook calling ResolveClient for the same client_id without a deadline joined the in-flight resolution and waited on itself. Neither call ever returned, and the resolution held a MaxConcurrentResolutions slot. A run was still stuck after 20 s, and with one slot an unrelated resolution got ErrTooManyResolutions.

The fix:

  • Behaviour: before the hook is called, the failure is now recorded on the in-flight resolution itself, bounded like a remembered failure. A request finding it there, the hook's own included, is answered at once instead of waiting.
  • Unchanged: when the hook is called relative to the result being published, and how a panic in the hook is handled for requests already waiting.
  • Docs: the OnResolutionFailure doc comment, server.Config and the federation guide now say a hook may resolve the same client_id, and that resolving a different one needs a slot of its own.

Tests

  • E-6: a fake transport moves the clock past the chain's exp during the Trust Anchor fetch, and during the RP's jwks_uri fetch. Cases cover long past exp, just past the skew, within the skew, before exp, and no time passing, for both ResolveClient and the key source.
  • E-7: a re-entrant hook with no deadline, with the failure forgotten, and with the failure memory full. A 5-second guard fails these tests instead of hanging the suite.
  • Without the fixes: each new test fails.
  • Mutants: five new, plus one existing mutant re-anchored. All six are killed.
  • Suites: the race suite, sqlstore and every example module pass, and lint is clean. Both federation fuzz targets pass 60-second runs.

Nothing on the wire changes for valid flows. Conformance is running anyway, since the federation plans exercise Resolve.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

osanderson and others added 3 commits November 26, 2026 07:16
Resolver.Resolve read the clock once, when it started, and verified
every statement it fetched at that time. A resolution whose fetches
outlasted the chain's earliest exp therefore returned a chain that had
already expired, and AutomaticClientRepository handed the requests
waiting on that resolution a client, and its keys, registered from it.
The cache itself was not extended past the chain's expiry: its entry
expired with the chain, so only the requests sharing that resolution
were answered from the expired chain.

Resolve now checks ResolvedEntity.ExpiresAt against the clock again
when it finishes, with the MaxClockSkew tolerance each statement's exp
was checked with, and refuses a chain that has expired by then.
Automatic registration repeats the check after building the
registration, since fetching the RP's jwks_uri can take the chain past
its expiry after Resolve returned. Such a registration fails like any
other: invalid_client for the client, reported to OnResolutionFailure
and remembered for FailureCacheAge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lient_id

OnResolutionFailure runs on the resolution's goroutine before the
resolution finishes. A hook calling ResolveClient for the same
client_id relied on the failure having been remembered just before it
ran; when it had not been (the memory of failures full, which any
caller can bring about by naming enough failing client_ids, or the
hook outlasting FailureCacheAge) the call joined the in-flight
resolution and waited on the hook that was waiting on it. With no
deadline on the call that wait never ended: the hook, the requests
sharing the resolution and its place under MaxConcurrentResolutions
were held for good, so enough of them refused every new resolution
with ErrTooManyResolutions.

The failure is now also recorded on the in-flight resolution before
the hook is called, bounded as a remembered failure is, and a request
for that client_id that finds it there gets it at once instead of
waiting. That covers the hook's own calls, whatever context they
carry, and makes the documented promise that a request arriving while
the hook runs is answered without joining the resolution hold even
when the failure could not be remembered. The hook's documentation now
says a hook may resolve the same client_id and what it gets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ooks

Cover the chain expiry check at the end of Resolve and after building
an automatic registration, its clock-skew tolerance, and the failure
published on an in-flight resolution for OnResolutionFailure. The
remembered-before-hook mutant moves past the new publishFailure call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@osanderson
osanderson merged commit 125875e into main Nov 25, 2026
34 checks passed
@osanderson
osanderson deleted the fix/audit-e6-e7 branch November 25, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant