Skip to content

fix(did): apply the resolver timeout to did:jwks fetches - #261

Open
furkan3152 wants to merge 3 commits into
agentcommercekit:mainfrom
furkan3152:fix/did-jwks-timeout
Open

furkan3152 wants to merge 3 commits into
agentcommercekit:mainfrom
furkan3152:fix/did-jwks-timeout

Conversation

@furkan3152

@furkan3152 furkan3152 commented Nov 2, 2026 •

Copy link
Copy Markdown

getDidResolver() applies webOptions.timeout (default 5000ms, added in #129) to did:web fetches but not to did:jwks. The did:jwks resolver gets its own fetch wrapper that only sets the redirect policy and passes no AbortSignal, so resolving did:jwks:<host> waits on that host with no bound. This sits under verifyJwt, verifyParsedCredential, verifyPaymentReceipt and the A2A verifiers, so a token whose iss is a did:jwks DID on a stalling host holds verification open, across up to three requests (JWKS, OpenID configuration, jwks_uri).

Repro: run a local server that accepts connections and never responds. With the default getDidResolver(), did:web:127.0.0.1%3A<port> returns notFound after ~5s, while did:jwks:127.0.0.1%3A<port> is still pending after 15s. With this change it fails with a timeout after ~5s.

Changes:

  • get-did-resolver.ts: the did:jwks fetch wrapper sets AbortSignal.timeout(timeout) (combined with a caller signal via AbortSignal.any), using webOptions.timeout ?? DEFAULT_TIMEOUT_MS.
  • web-did-resolver.ts: the 5000ms default is a shared DEFAULT_TIMEOUT_MS.
  • Two tests that fail on main; @agentcommercekit/did patch changeset.

pnpm run check, pnpm run knip and pnpm run check:format pass. Independent of #193/#200, which add a URL policy to the same path but no timeout.

AI usage: Claude Code assisted with this change; I reviewed it and the test results.

Summary by CodeRabbit

  • New Features
    • did:jwks resolution now uses the configured fetch timeout, defaulting to 5 seconds, for JWKS and OpenID configuration requests. Requests that exceed the timeout are aborted, and resolution reports the DID as not found.
    • Timed-out results are not cached, so a later resolution can succeed. Custom fetch implementations must honor abort signals for timeouts to take effect.

getDidResolver() wraps fetch for the did:jwks resolver to inject the
redirect policy, but passed no AbortSignal, so the webOptions.timeout
(default 5000ms) added for did:web in agentcommercekit#129 never bounded did:jwks.
A did:jwks host that stalls its response held resolution, and any
verification waiting on it, open with no bound from this library.

Abort each did:jwks fetch (JWKS, OpenID configuration, jwks_uri) after
the same timeout.
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9d73461a-17a8-4ff6-9143-dd0e124763e3
Commits

Reviewing files that changed from the base of the PR and between 7ec4aca and 4105e18.

Files selected for processing: 2
  • packages/did/src/did-resolvers/get-did-resolver.test.ts
  • packages/did/src/did-resolvers/get-did-resolver.ts
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c44a52f6-c50b-4f40-acbd-c6680b7ef4c2
Commits

Reviewing files that changed from the base of the PR and between 184e5ea and 7ec4aca.

Files selected for processing: 3
  • .changeset/did-jwks-fetch-timeout.md
  • packages/did/src/did-resolvers/get-did-resolver.test.ts
  • packages/did/src/did-resolvers/get-did-resolver.ts
Files skipped from review as they are similar to previous changes: 1
  • .changeset/did-jwks-fetch-timeout.md

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Walkthrough

The did:jwks resolver now applies a configurable fetch timeout, defaulting to 5000 ms. It combines the timeout signal with any caller-provided signal. Timed-out resolutions return notFound. Tests cover configured and default timeouts, caching, and abort behavior.

Changes

did:jwks Timeout

Layer / File(s) Summary
Timeout configuration and fetch propagation
packages/did/src/did-resolvers/web-did-resolver.ts, packages/did/src/did-resolvers/get-did-resolver.ts, packages/did/src/did-resolvers/get-did-resolver.test.ts, .changeset/did-jwks-fetch-timeout.md
The resolver exports and uses a shared 5000 ms default. did:jwks fetches use the configured timeout or that default and combine the timeout signal with any caller-provided signal. Timed-out internal errors return as notFound. Tests cover abort signals, default timeouts, and a later successful resolution after a timeout. The changeset documents the timeout and custom-fetch signal requirement.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: efedurmaz16

Merge Risk: Low · previous review 7ec4a

A later discovery failure can be reported with the wrong error when an earlier fetch’s timeout expires. Clean up the listener before merging, or accept this bounded risk.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: applying the resolver timeout to did:jwks fetches.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 3 files. (1 skipped: 1 unsupported.)

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

did-resolver's in-memory cache stores every result except notFound, and
the did:jwks resolver reports any fetch failure as internalError. With
cache: true, a transient timeout was cached and the DID never resolved
again. Report a timeout as notFound, as did:web does.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

The timeout listener fired when a fetch's timer expired even if that
fetch had already settled, so a later non-timeout failure in the same
resolution could be reported as notFound. Check the timeout signal when
the fetch fails instead.

This branch has not been deployed

No deployments
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