fix(discovery): handle data: URIs inline in fetchAgentCard#238
Open
uibeka wants to merge 3 commits intoConway-Research:mainfrom
Open
fix(discovery): handle data: URIs inline in fetchAgentCard#238uibeka wants to merge 3 commits intoConway-Research:mainfrom
uibeka wants to merge 3 commits intoConway-Research:mainfrom
Conversation
Agents storing ERC-8004 metadata as inline data:application/json URIs (base64 or percent-encoded) are invisible to discover_agents. The SSRF filter in isAllowedUri() correctly blocks network requests to non-https/ ipfs URLs, but data: URIs are inline payloads that make no network request and pose no SSRF risk. Add a handler in fetchAgentCard() that intercepts data:application/json URIs before the SSRF check, decodes the payload inline, enforces the existing maxCardSizeBytes size limit, and routes through validateAgentCard for schema validation. No changes to the SSRF filter itself. This makes ~18-20 agents (~90% of the current ecosystem) visible to discovery that were previously blocked.
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
Author
|
@unifiedh Addressed Devin's review comment - tightened the MIME type check. Ready for merge. |
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.
Problem
Agents storing ERC-8004 metadata as inline
data:application/json;base64,...URIs are invisible todiscover_agents. The SSRF filter inisAllowedUri()blocks them becausedata:is not in thehttps:/ipfs:protocol allowlist. However,data:URIs are inline encoded payloads that make no network request — there is zero SSRF risk.This affects approximately 90% of registered agents on Base, which use inline
data:URIs for their on-chain agent cards (standard ERC-8004 practice). The framework successfully scans 20+ on-chain mint events, then fails to read 18+ of their metadata URIs, causingdiscover_agentsto report only 2-4 agents instead of the full ecosystem.Root Cause
fetchAgentCard()passes all URIs throughisAllowedUri()before fetching. The allowlist only includeshttps:andipfs:.data:URIs fail this check and are logged as "Blocked URI (SSRF protection)" — a misclassification since no network request is involved.Fix
Add a handler in
fetchAgentCard()that interceptsdata:application/jsonURIs before the SSRF check. The handler:data:application/jsonURIs (rejects other MIME types)Buffer.from()or percent-encoded viadecodeURIComponent())maxCardSizeBytessize limit (matching the network fetch path's protection against oversized responses)validateAgentCard()for schema validationNo changes to
isAllowedUri()or the SSRF filter. The network fetch path for HTTPS/IPFS URIs is completely untouched. The only change is a new code block insidefetchAgentCard()that handlesdata:URIs as a separate path.Security Considerations
isAllowedUri()data:application/jsonaccepted;data:text/html,data:image/png, etc. are rejectedmaxCardSizeBytes(same limit as network-fetched cards)validateAgentCard()applied identically to data: URI cards and network-fetched cardsdata:URIs are decoded in-process from the URI string itselfImpact
discover_agentsnull(identical to current behavior when data: URIs are blocked)Testing
pnpm build— zero errorspnpm test— all existing + 12 new tests pass