Skip to content

[#639] Harden resolveAgentURI with timeout and validation#649

Merged
realproject7 merged 3 commits intomainfrom
task/639-agent-uri-validation
Mar 30, 2026
Merged

[#639] Harden resolveAgentURI with timeout and validation#649
realproject7 merged 3 commits intomainfrom
task/639-agent-uri-validation

Conversation

@realproject7
Copy link
Copy Markdown
Owner

Summary

  • 5s timeout: AbortController on remote fetches (https/ipfs) prevents hangs from slow servers
  • Response validation: Checks res.ok before parsing body
  • 50KB size limit: Enforced on all payload types (remote, data: URI, raw JSON)
  • Graceful error handling: Entire function wrapped in try/catch, returns {} on any failure instead of throwing

Fixes #639
Tracks realproject7/agent-os#312

Test plan

  • Remote fetch with slow server times out after 5s (returns {})
  • Non-200 responses return {} (not crash)
  • Invalid JSON returns {} gracefully
  • Oversized data: URI payloads return {}
  • Normal agent URIs still resolve correctly
  • Build passes

🤖 Generated with Claude Code

- Add 5s AbortController timeout for remote fetches (https/ipfs)
- Check res.ok before parsing response body
- Enforce 50KB size limit on all payloads (remote, data: URI, raw JSON)
- Wrap entire function in try/catch for graceful JSON parse error handling
- Return empty object instead of throwing on any failure

Fixes #639

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
plotlink Ignored Ignored Mar 30, 2026 6:59pm

Request Review

Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

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

Verdict: REQUEST CHANGES

Summary

The timeout and graceful-failure work is headed in the right direction, but the oversized remote-response protection is still incomplete.

Findings

  • [high] The remote size check happens only after res.text() has already buffered the entire response body, so an oversized agent URI response can still be fully downloaded into memory before being rejected.
    • File: lib/contracts/erc8004.ts:248
    • Suggestion: Reject oversized remote payloads before or during body consumption. At minimum, gate on Content-Length when present; ideally stream the body and abort once the accumulated byte count exceeds MAX_URI_BYTES.

Decision

Requesting changes because the current implementation does not yet safely handle oversized remote responses, which is part of the issue's acceptance criteria.

Check Content-Length header for early rejection, then stream body
via ReadableStream reader and abort once accumulated bytes exceed
50KB — avoids buffering oversized responses into memory.

Addresses T2a review feedback on PR #649.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

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

Verdict: REQUEST CHANGES

Summary

The streamed size-cap fix addresses the earlier buffering issue, but the current implementation introduces a client-side runtime/bundle regression.

Findings

  • [high] resolveAgentURI() now uses Buffer.concat(...), but this helper is imported by the client component src/components/AgentManage.tsx, so the change adds a Node-only dependency into client code.
    • File: lib/contracts/erc8004.ts:267
    • Suggestion: Keep the streamed decoding browser-safe. For example, accumulate into a growing Uint8Array, or append decoded chunks via TextDecoder.decode(value, { stream: true }) and finalize once the reader completes.

Decision

Requesting changes because resolveAgentURI() is used from client-side code and the new Buffer dependency can break the runtime or bundle despite the size-limit fix itself being directionally correct.

Buffer.concat is Node-only and this module is imported by client
components. Use plain Uint8Array concatenation instead.

Addresses T2a review feedback on PR #649.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

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

Verdict: APPROVE

Summary

The hardening work now meets the requested scope: resolveAgentURI() adds the timeout, response validation, size limits, graceful parse failure handling, and the streamed body handling is now browser-safe for client-importable code.

Findings

  • None.

Decision

Approving on code review. The earlier oversized-response and client-runtime issues are addressed; remaining CI checks are still running but do not block the review verdict.

@realproject7 realproject7 merged commit 29f655b into main Mar 30, 2026
5 checks passed
@realproject7 realproject7 deleted the task/639-agent-uri-validation branch March 30, 2026 19:02
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.

Add timeout and validation for remote agent URI fetches

2 participants