feat(did): refuse redirects when resolving did:web by default - #133
Open
EfeDurmaz16 wants to merge 1 commit into
Open
feat(did): refuse redirects when resolving did:web by default#133EfeDurmaz16 wants to merge 1 commit into
EfeDurmaz16 wants to merge 1 commit into
Conversation
allowedHttpHosts is applied to the URL built from the DID, but the document fetch followed redirects, so the check only governed the first hop: a did:web served over https could redirect the resolver to plain http, or to a host the allowlist would have rejected. Because the redirect target is chosen by the DID's own host, this also turns resolution into an outbound request the issuer controls. did:web documents are served directly at a well-known path, so redirects are refused by default via redirect: "error". followRedirects: true restores the previous behavior for deployments that need it.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
WalkthroughThe Changesdid:web redirect handling
Estimated code review effort: 2 (Simple) | ~12 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
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.
What
getResolverfordid:webnow sendsredirect: "error"when fetching the DID document. A newfollowRedirects?: booleanoption (defaultfalse) restores the previous behavior.Why
allowedHttpHostsis applied to the URL built from the DID:The fetch that follows it used the platform default, which follows redirects. So the allowlist only governs the first hop: a
did:webresolved overhttpscan answer302 Location: http://…, and the resolver follows it to a scheme and host the check was there to reject.flowchart LR D["did:web:issuer.example"] --> C{"allowedHttpHosts<br/>allows http for this host?"} C -- no --> U["fetch https://issuer.example/.well-known/did.json"] U --> H{"host answers 302<br/>Location: http://internal/…"} H -->|before: redirect followed| BAD["request lands on the scheme<br/>and host the check rejected"] H -->|after: redirect error| OK["resolution fails as notFound"] classDef bad stroke-dasharray: 4 3 class BAD badBecause the redirect target is chosen by the DID's own host, this also makes resolution an outbound request an untrusted party controls. That matters for anything that resolves a DID before verifying a signature, which is the normal order: you need the document to check the signature. A server verifying an ACK-ID proof from an arbitrary issuer will fetch whatever that issuer's host points it at.
did:web documents are served directly at
/.well-known/did.json(or the configureddocPath), so refusing redirects costs legitimate resolution nothing. Deployments that genuinely sit behind a redirect can opt in.How
DidWebResolverOptionsgainsfollowRedirects?: boolean, documented with the reason, defaulting tofalse.fetchDidDocumentAtUrlpassesredirect: followRedirects ? "follow" : "error"alongside the existingmode: "cors".notFound) and the opt-in (redirect: "follow").Test plan
Found while building an ACK-ID identity-gated x402 demo, where a seller resolves buyer DIDs it has never seen before.
Implemented and tested by gpt 5.6-sol and fable 5, reviewed by me.
Summary by CodeRabbit
New Features
did:webdocuments.Documentation
followRedirects: true.