Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(ssrf): fetch creator-supplied metadata and logo URIs through the pinned guard
nirholasd0e4a1e28ed0
diff --git a/api/_lib/pumpfun-ws-feed.js b/api/_lib/pumpfun-ws-feed.jsindex f80a82767..2709c34a2 100644--- a/api/_lib/pumpfun-ws-feed.js+++ b/api/_lib/pumpfun-ws-feed.js@@ -6,6 +6,7 @@import WebSocket from 'ws';import { solPriceUsd as sharedSolPriceUsd } from './sol-price.js';import { pumpPortalWsUrl, handlePumpPortalAck, isPumpPortalRefusal } from './pumpportal.js';+import { fetchSafePublicUrlPinned } from './ssrf-guard.js';const RECONNECT_DELAY_MS = 2_000;const MAX_RECONNECTS = 5;@@ -43,6 +44,7 @@ function markSeen(sig) {return true;}const META_TIMEOUT_MS = 2_500;+const META_MAX_BYTES = 256 * 1024;// SOL/USD via the shared 7-source failover helper (CoinGecko → Jupiter → Kraken// → Coinbase → DefiLlama → DIA → Bitfinex, itself cached ~60s and shared across@@ -60,7 +62,15 @@ async function fetchMeta(uri) {try {const ctrl = new AbortController();const tid = setTimeout(() => ctrl.abort(), META_TIMEOUT_MS);- const r = await fetch(uri, { signal: ctrl.signal });+ // The uri is whatever the coin's creator put in its metadata, so it goes+ // through the pinned SSRF guard: no private or metadata address on any+ // redirect hop, and a byte cap while streaming. Fields from the response+ // are broadcast to every stream subscriber.+ const r = await fetchSafePublicUrlPinned(+ uri,+ { signal: ctrl.signal, headers: { accept: 'application/json' } },+ { allowHttp: true, maxBytes: META_MAX_BYTES },+ );clearTimeout(tid);if (!r.ok) return null;const d = await r.json();diff --git a/api/_lib/solana-token-meta.js b/api/_lib/solana-token-meta.jsindex f0500c407..8a76584db 100644--- a/api/_lib/solana-token-meta.js+++ b/api/_lib/solana-token-meta.js@@ -16,6 +16,7 @@ import {} from '@solana/spl-token';import { getConnection, solanaPubkey } from './pump.js';import { isRpcOutageError, rpcUnavailableError } from './rpc-degrade.js';+import { fetchSafePublicUrlPinned } from './ssrf-guard.js';const METADATA_PROGRAM = new PublicKey('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s');const NAME_MAX = 32;@@ -119,11 +120,18 @@ async function fetchOffchainJson(uri) {if (!url) return null;let res;try {- res = await fetch(url, {- redirect: 'follow',- signal: AbortSignal.timeout(METADATA_FETCH_TIMEOUT_MS),- headers: { accept: 'application/json' },- });+ // The metadata URI is whatever the mint's creator wrote on-chain, so it is+ // fetched through the pinned SSRF guard: private and metadata addresses+ // are refused on every redirect hop, and the byte cap holds while+ // streaming.+ res = await fetchSafePublicUrlPinned(+ url,+ {+ signal: AbortSignal.timeout(METADATA_FETCH_TIMEOUT_MS),+ headers: { accept: 'application/json' },+ },+ { allowHttp: true, maxBytes: MAX_OFFCHAIN_JSON_BYTES },+ );} catch {return null;}@@ -154,11 +162,14 @@ export async function fetchTokenImage(imageUrl) {if (!url) return null;let res;try {- res = await fetch(url, {- redirect: 'follow',- signal: AbortSignal.timeout(IMAGE_FETCH_TIMEOUT_MS),- headers: { accept: 'image/png, image/jpeg, image/webp, image/*' },- });+ res = await fetchSafePublicUrlPinned(+ url,+ {+ signal: AbortSignal.timeout(IMAGE_FETCH_TIMEOUT_MS),+ headers: { accept: 'image/png, image/jpeg, image/webp, image/*' },+ },+ { allowHttp: true, maxBytes: MAX_IMAGE_BYTES },+ );} catch {return null;}diff --git a/api/_lib/validation-attest.js b/api/_lib/validation-attest.jsindex 500650861..948b15817 100644--- a/api/_lib/validation-attest.js+++ b/api/_lib/validation-attest.js@@ -28,7 +28,12 @@ import { env } from './env.js';import { CHAIN_BY_ID, VALIDATION_REGISTRY_ABI, validationRegistryFor } from './erc8004-chains.js';import { evmFallbackProvider } from './evm/rpc.js';import { putObject, publicUrl } from './r2.js';-import { assertSafePublicUrl, SsrfBlockedError } from './ssrf-guard.js';+import {+ assertSafePublicUrl,+ fetchSafePublicUrlPinned,+ MaxBytesExceededError,+ SsrfBlockedError,+} from './ssrf-guard.js';import { inspectModel, suggestOptimizations } from './model-inspect.js';import {buildGlbReport,@@ -77,14 +82,26 @@ export async function validateGlb(glbUrl, validatedAt) {throw err;}+ // Pinned fetch: every redirect hop is re-validated and the socket connects+ // to the address that was checked, so a public host answering 302 to the+ // metadata server (or rebinding its DNS) cannot pull internal bytes into a+ // report that is then pinned publicly. The byte cap is enforced while+ // streaming, before the body is buffered.let upstream;try {- upstream = await fetch(parsed.toString(), {- redirect: 'follow',- headers: { accept: 'model/gltf-binary,model/gltf+json,application/octet-stream' },- signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),- });+ upstream = await fetchSafePublicUrlPinned(+ parsed.toString(),+ {+ headers: { accept: 'model/gltf-binary,model/gltf+json,application/octet-stream' },+ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),+ },+ { allowHttp: true, maxBytes: MAX_FETCH_BYTES },+ );} catch (err) {+ if (err instanceof SsrfBlockedError) throw new AttestError('invalid_glb_url', err.message);+ if (err instanceof MaxBytesExceededError) {+ throw new AttestError('glb_too_large', `GLB is ${err.observed} bytes; max ${MAX_FETCH_BYTES}`);+ }throw new AttestError('glb_fetch_failed', `could not fetch GLB: ${err.message}`);}if (!upstream.ok) {diff --git a/api/oracle/og.js b/api/oracle/og.jsindex 1c09b1049..c56284749 100644--- a/api/oracle/og.js+++ b/api/oracle/og.js@@ -19,6 +19,7 @@import { cors, wrap } from '../_lib/http.js';import { sql } from '../_lib/db.js';+import { fetchOgImage } from '../_lib/og-avatar.js';import { isQuoteMint } from '../_lib/quote-mints.js';import { pumpFetchJson } from '../_lib/pump-feed-fetch.js';import { fetchTokenMarketData } from '../_lib/market/token-market.js';@@ -83,16 +84,12 @@ async function fetchLogoBase64(imageUri) {const url = imageUri.startsWith('ipfs://')? `https://ipfs.io/ipfs/${imageUri.slice(7)}`: imageUri;- try {- const resp = await fetch(url, { signal: AbortSignal.timeout(3000) });- if (!resp.ok) return null;- const ct = resp.headers.get('content-type') || 'image/png';- const buf = await resp.arrayBuffer();- const b64 = Buffer.from(buf).toString('base64');- return `data:${ct};base64,${b64}`;- } catch {- return null;- }+ // The logo URI is chosen by whoever launched the coin. fetchOgImage refuses+ // private and metadata addresses on every redirect hop, caps the bytes, and+ // only accepts a bare image media type, so neither internal responses nor a+ // quote-breaking content-type can end up inside this same-origin SVG.+ const img = await fetchOgImage(url, { timeoutMs: 3000 });+ return img ? `data:${img.ct};base64,${img.b64}` : null;}async function buildCardData(mint) {diff --git a/api/pump/launch-og.js b/api/pump/launch-og.jsindex 93dbb775b..d30edd3a9 100644--- a/api/pump/launch-og.js+++ b/api/pump/launch-og.js@@ -27,6 +27,7 @@import { cors, method, wrap } from '../_lib/http.js';import { sql } from '../_lib/db.js';+import { fetchOgImage } from '../_lib/og-avatar.js';import { pumpFetchJson } from '../_lib/pump-feed-fetch.js';const MINT_RE = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;@@ -66,20 +67,15 @@ function fmtNum(v) {// we just omit the image; the card still renders fine without it.async function fetchLogoBase64(imageUri) {if (!imageUri) return null;- // pump.fun uses IPFS CIDs — resolve via a fast gateway.const url = imageUri.startsWith('ipfs://')? `https://ipfs.io/ipfs/${imageUri.slice(7)}`: imageUri;- try {- const resp = await fetch(url, { signal: AbortSignal.timeout(3000) });- if (!resp.ok) return null;- const ct = resp.headers.get('content-type') || 'image/png';- const buf = await resp.arrayBuffer();- const b64 = Buffer.from(buf).toString('base64');- return `data:${ct};base64,${b64}`;- } catch {- return null;- }+ // The logo URI is chosen by whoever launched the coin. fetchOgImage refuses+ // private and metadata addresses on every redirect hop, caps the bytes, and+ // only accepts a bare image media type, so neither internal responses nor a+ // quote-breaking content-type can end up inside this same-origin SVG.+ const img = await fetchOgImage(url, { timeoutMs: 3000 });+ return img ? `data:${img.ct};base64,${img.b64}` : null;}async function buildCardData(mint) {diff --git a/tests/solana-token-meta-token2022.test.js b/tests/solana-token-meta-token2022.test.jsindex 6efa255ce..197439209 100644--- a/tests/solana-token-meta-token2022.test.js+++ b/tests/solana-token-meta-token2022.test.js@@ -74,6 +74,13 @@ vi.mock('../api/_lib/pump.js', () => ({}),}));+// The off-chain read goes through the pinned SSRF guard, which opens its own+// socket. Route it to the stubbed global fetch so these cases stay offline; the+// guard itself is covered in tests/token-metadata-ssrf.test.js.+vi.mock('../api/_lib/ssrf-guard.js', () => ({+ fetchSafePublicUrlPinned: (url, init) => globalThis.fetch(url, init),+}));+const { fetchTokenMeta } = await import('../api/_lib/solana-token-meta.js');// The off-chain JSON document is a network read; every case here either has no