feat(did): add did:web key resolver with SSRF protection (RFC-008 §17.1)#71
Open
feat(did): add did:web key resolver with SSRF protection (RFC-008 §17.1)#71
Conversation
Implements WebResolver for resolving did:web identifiers by fetching DID documents over HTTPS and extracting public keys. New files: - pkg/did/document.go: DID Document, VerificationMethod, JWK types - pkg/did/web_resolver.go: WebResolver with SSRF-safe HTTP client - pkg/did/web_resolver_test.go: 16 tests covering all security requirements Security features (RFC-008 §17.1): - HTTPS required in production (AllowHTTP=false by default) - SSRF protection: blocks localhost, 127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, link-local, metadata endpoints - Response size limits (default 64KB) - Request timeouts (default 10 seconds) - No redirect following (prevents SSRF via redirect) - Document caching with configurable TTL (default 5 minutes) Key formats supported: - Ed25519VerificationKey2020 (publicKeyMultibase, base58btc) - JsonWebKey2020 (publicKeyJwk, OKP/Ed25519) Also adds NewCompositeKeyResolver to pkg/envelope/verifier.go that routes did:key to the local resolver and did:web to WebResolver. Tests: - Basic resolve with JWK document - Path segment URL construction (did:web:example.com:agents:worker) - Key ID fragment matching in multi-key documents - SSRF: localhost, private IPs (10/172.16/192.168/169.254/::1) - SSRF: blocked hostnames (metadata.google.internal) - Oversized document rejection - Timeout enforcement - Cache hit verification (no second HTTP request) - Multibase key decoding - Invalid JWK curve rejection - HTTPS requirement enforcement - Composite resolver delegation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds did:web key resolution support to enable envelope authority chain verification across organizations by fetching DID documents over HTTP(S), and wires it into envelope verification via a composite key resolver.
Changes:
- Introduces minimal DID Document types (
Document,VerificationMethod,JWK) used for extracting keys. - Adds a
did.WebResolverthat fetches and caches DID documents and supports Ed25519 keys viapublicKeyMultibaseandpublicKeyJwk. - Adds
envelope.NewCompositeKeyResolver()to resolvedid:keylocally anddid:webvia the new resolver, plus a new resolver-focused test suite.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| pkg/envelope/verifier.go | Adds a composite key resolver to route did:key to local parsing and did:web to the web resolver. |
| pkg/did/document.go | Defines minimal DID Document/JWK structs used by the resolver. |
| pkg/did/web_resolver.go | Implements did:web document fetching, SSRF-related transport logic, caching, and key extraction/decoding. |
| pkg/did/web_resolver_test.go | Adds tests covering key extraction, SSRF-related helpers, caching, and error scenarios. |
| } | ||
| if parsed.IsKeyDID() { | ||
| return DefaultKeyResolver(ctx, didStr, kid) | ||
| } |
Comment on lines
+105
to
+107
| if r.CacheTTL == 0 { | ||
| r.CacheTTL = DefaultCacheTTL | ||
| } |
Comment on lines
+109
to
+113
| if r.Client != nil { | ||
| r.client = r.Client | ||
| } else { | ||
| r.client = &http.Client{ | ||
| Timeout: DefaultResolveTimeout, |
Comment on lines
+309
to
+310
| return dialer.DialContext(ctx, network, addr) | ||
| } |
Comment on lines
+185
to
+189
| if strings.HasPrefix(kid, didStr+"#") || strings.HasPrefix(kid, "#") { | ||
| targetID = kid | ||
| } else { | ||
| targetID = didStr + "#" + kid | ||
| } |
Comment on lines
+48
to
+76
| // Setup test server | ||
| didStr := "did:web:example.com" | ||
| kid := "key-0" | ||
| pub, _, docBytes := testKeyAndDocument(t, didStr, kid) | ||
|
|
||
| server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| assert.Equal(t, "/.well-known/did.json", r.URL.Path) | ||
| w.Header().Set("Content-Type", "application/did+json") | ||
| w.Write(docBytes) | ||
| })) | ||
| defer server.Close() | ||
|
|
||
| resolver := &WebResolver{ | ||
| Client: server.Client(), | ||
| AllowHTTP: true, // test server uses HTTP | ||
| CacheTTL: time.Minute, | ||
| } | ||
| resolver.initOnce.Do(resolver.init) | ||
|
|
||
| // Override document URL by testing with a DID that points to our test server | ||
| // We'll directly test resolveDocument with the test server URL | ||
| ctx := context.Background() | ||
| doc, err := resolver.resolveDocument(ctx, server.URL+"/.well-known/did.json") | ||
| require.NoError(t, err) | ||
| assert.Equal(t, didStr, doc.ID) | ||
|
|
||
| // Extract key | ||
| key, err := resolver.extractKey(doc, didStr, kid) | ||
| require.NoError(t, err) |
Comment on lines
+365
to
+369
| // NewCompositeKeyResolver is in pkg/envelope - test the integration pattern | ||
| func NewCompositeKeyResolver(webResolver *WebResolver) func(ctx context.Context, didStr string, kid string) (interface{}, error) { | ||
| return func(ctx context.Context, didStr string, kid string) (interface{}, error) { | ||
| parsed, err := Parse(didStr) | ||
| if err != nil { |
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
Implements the
did:webkey resolver for RFC-008 §17.1, enabling cross-organization authority chain verification. This is PR E from the RFC-008 implementation plan.What it does
Allows the envelope verifier to resolve public keys from
did:webidentifiers by fetching DID documents over HTTPS. This is needed for authority chains that span multiple organizations (each org hosts their owndid.json).Security (RFC-008 §17.1 + RFC-002 SSRF)
The WebResolver includes comprehensive SSRF protection:
AllowHTTPflag)Files Changed
pkg/did/document.gopkg/did/web_resolver.gopkg/did/web_resolver_test.gopkg/envelope/verifier.goNewCompositeKeyResolver()Key Formats Supported
Ed25519VerificationKey2020withpublicKeyMultibase(base58btc)JsonWebKey2020withpublicKeyJwk(OKP/Ed25519)Usage
Tests (16 tests)
Dependencies