Skip to content

fix(sovereign-metadata): harden MST resolver — timeout, 4xx semantics, bounds#10

Merged
zkSoju merged 1 commit into
mainfrom
fix/mst-image-hardening
May 30, 2026
Merged

fix(sovereign-metadata): harden MST resolver — timeout, 4xx semantics, bounds#10
zkSoju merged 1 commit into
mainfrom
fix/mst-image-hardening

Conversation

@zkSoju
Copy link
Copy Markdown
Contributor

@zkSoju zkSoju commented May 30, 2026

Post-ship hardening of the MST image resolver (shipped in #9), from a FAGAN multimodel review (Opus-skeptic + GPT-5.5 + Composer) cross-checked with self-review. Happy path unchanged; 126 tests pass.

  • timeout — bound the upstream storage-api fetch with an AbortController (METADATA_FETCH_TIMEOUT_MS, default 8s). undici's global fetch has no short default; a stalled/trickling origin could tie up the request ~300s. (FAGAN-confirmed + self-flagged.)
  • 4xx semantics — only 403/404NotFoundError; 401/429/etc → thrown Error. A throttle or auth blip no longer masquerades as "token absent" (or surfaces as a misleading 404 to API callers).
  • boundary validation — numeric tokenId check + encodeURIComponent in fetchMstMetadata/mstMetadataUrl, so they're safe in isolation, not only behind getNftMetadata.
  • bounds — cap mapped attributes (MAX_ATTRIBUTES=64) so a hostile/buggy upstream array can't drive unbounded work/payload.

Tests: +2 (abort-signal wiring · 429 ≠ NotFound).

context: part of the MST mint-image enrichment closeout. Companion PR in freeside-characters hardens the consumer (HTTP client self-catch + image-URL allowlist).
🤖 Generated with Claude Code

… bounds)

Post-ship hardening from a FAGAN multimodel review + self-review of the
shipped MST image resolver. No behavior change for the happy path.

- Bound the upstream storage-api fetch with an AbortController timeout
  (METADATA_FETCH_TIMEOUT_MS, default 8s). undici's global fetch has no short
  default — a stalled/trickling origin could otherwise tie up the request ~300s.
- Stop collapsing ALL 4xx into NotFound: only 403 (unminted) / 404 (absent) →
  NotFoundError; 401/429/etc → thrown Error. A throttle or auth blip no longer
  masquerades as "token doesn't exist" (and won't surface as a 404 to API callers).
- Validate the numeric tokenId at the exported fetchMstMetadata boundary too,
  and encodeURIComponent the path segment — the helper is now safe in isolation,
  not only behind getNftMetadata's validation.
- Cap mapped attributes (MAX_ATTRIBUTES=64) so a hostile/buggy upstream array
  can't drive unbounded work/payload (real MST tokens carry ~19).

Tests: +2 (abort-signal wiring, 429≠NotFound). Full suite 126 pass.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e337bd56b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/sovereign-metadata.ts
Comment on lines +27 to +29
const METADATA_FETCH_TIMEOUT_MS = Number(
process.env.METADATA_FETCH_TIMEOUT_MS ?? 8000
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Default invalid timeout overrides before scheduling fetches

When METADATA_FETCH_TIMEOUT_MS is present but empty or non-numeric, this Number(...) expression produces 0/NaN instead of falling back to the 8s default; setTimeout(..., 0/NaN) then aborts real MST metadata fetches almost immediately in that deployment configuration. Since this is an ops override, validate that the parsed value is a finite positive duration before using it, and otherwise keep the default.

Useful? React with 👍 / 👎.

@zkSoju zkSoju merged commit 81adcbf into main May 30, 2026
3 checks passed
@zkSoju zkSoju deleted the fix/mst-image-hardening branch May 30, 2026 19:22
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