feat: client-side DPoP nonce caching across calls - #170
Merged
Conversation
…nging None of the three nonce-aware call sites (the token endpoint, PAR, ResourceClient.Do) carried a server-provided nonce forward to the next, independent call — each only reacted to a challenge within the one call already in flight. So an AS/RS that proactively reissues a nonce on every success (this session's own server/resource work does exactly this via NextDPoPNonce) got no benefit: every call paid the extra round trip, not just the first. Adds an optional Dependencies.DPoPNonceCache, following the same opt-in shape Decryption and Clock/SystemClock already use — nil disables it entirely, exactly today's behavior; a caller opts in explicitly with NewInMemoryDPoPNonceCache() or their own implementation. It's a hint, not a ledger: a missing or stale cached value costs one extra challenge/retry round trip, recovered by the existing retry logic exactly as if the cache didn't exist. PAR and the token endpoint share one cache scope, matching how server's own Dependencies.Nonces already treats them as one shared nonce space — a nonce obtained from either primes the other, so PAR's own success can prime the very first token request of a flow. Resource calls are scoped per resource-server origin, since Do can be pointed at any URL and RFC 9449 §9 nonces are per-RS. Verified against the live OIDF conformance suite: unaffected, since cmd/conformance-client doesn't wire the cache in — this change is purely additive and behaviorally invisible unless opted into. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Closes a gap surfaced while testing the recent DPoP nonce-challenge work: none of
client's three nonce-aware call sites (token endpoint, PAR,ResourceClient.Do) carried a server-provided nonce forward to the next, independent call — each only reacted to a challenge within the one call already in flight. An AS/RS that proactively reissues a nonce on every success (which this session's ownserver/resourcework does viaNextDPoPNonce) got no benefit from it: every call paid the extra round trip, not just the first.Dependencies.DPoPNonceCache, following the same opt-in shapeDecryptionandClock/SystemClockalready use — nil disables it entirely (today's exact behavior); a caller opts in explicitly withNewInMemoryDPoPNonceCache()(shipped, mutex-guarded) or their own implementation. It's a hint, not a ledger — a missing or stale cached value just costs one extra challenge/retry round trip, recovered by the existing retry logic exactly as if the cache didn't exist.server.Dependencies.Noncesalready treats them as one shared nonce space — a nonce obtained from either primes the other, so PAR's own success can prime the very first token request of a flow (confirmed by the new test, better than originally expected). Resource calls are scoped per resource-server origin, sinceDocan be pointed at any URL and RFC 9449 §9 nonces are per-RS.Test plan
go build ./...,go vet ./...,go test ./... -raceall cleanInMemoryDPoPNonceCacheround-trip/isolation/concurrency, a full two-flow test proving PAR+token both skip their retry on the second flow once cached, a stale-cache-still-recovers test, and the equivalent forResourceClient.DoDPoPNonceCache) passes unchanged — confirms the optimization is fully opt-incmd/conformance-clientdoesn't wire the cache in, so this change is behaviorally invisible unless opted into