Skip to content

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.

Integrate SSRF guard for safe URL fetching in scene graph and Solana agents

nirholasf2d47de6b84b
diff --git a/api/_lib/scene-graph-compose.js b/api/_lib/scene-graph-compose.js
index 0c3dd3d91..794cdbaa8 100644
--- a/api/_lib/scene-graph-compose.js
+++ b/api/_lib/scene-graph-compose.js
@@ -23,6 +23,7 @@ import { ALL_EXTENSIONS, KHRLightsPunctual } from '@gltf-transform/extensions';
import { mergeDocuments, prune, dedup, unpartition } from '@gltf-transform/functions';
import * as THREE from 'three';
import { MOOD_LIGHT, ISLAND_RADIUS, normalizeDiorama } from '../../src/diorama/schema.js';
+import { fetchSafePublicUrlPinned } from './ssrf-guard.js';
// Matches TARGET_FOOTPRINT in src/diorama/renderer.js — keeps a forged object's
// on-screen size in the exported GLB identical to the live diorama stage.
@@ -291,19 +292,18 @@ async function fetchGlb(url) {
if (!/^https?:\/\//i.test(url)) {
throw new Error(`refusing non-http glbUrl: ${url}`);
}
- const controller = new AbortController();
- const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
- try {
- const res = await fetch(url, { signal: controller.signal });
- if (!res.ok) throw new Error(`GLB fetch failed: HTTP ${res.status}`);
- const buf = new Uint8Array(await res.arrayBuffer());
- if (buf.byteLength > MAX_SOURCE_GLB_BYTES) {
- throw new Error(`GLB too large (${buf.byteLength} bytes)`);
- }
- return buf;
- } finally {
- clearTimeout(timer);
- }
+ // glbUrl is caller-controlled (diorama objects arrive in the POST body, and
+ // the same surface is reachable via the export_scene MCP tool), so the fetch
+ // goes through the pinned SSRF guard: full DNS validation, IP pinned at
+ // connect, every redirect hop re-validated. Otherwise a crafted diorama
+ // turns the export endpoint into a blind SSRF from the Cloud Run network.
+ const res = await fetchSafePublicUrlPinned(
+ url,
+ { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) },
+ { maxBytes: MAX_SOURCE_GLB_BYTES },
+ );
+ if (!res.ok) throw new Error(`GLB fetch failed: HTTP ${res.status}`);
+ return new Uint8Array(await res.arrayBuffer());
}
// ── Math helpers ─────────────────────────────────────────────────────────
diff --git a/api/_lib/solana-agents-crawl.js b/api/_lib/solana-agents-crawl.js
index a786b5f32..3bfcfaccf 100644
--- a/api/_lib/solana-agents-crawl.js
+++ b/api/_lib/solana-agents-crawl.js
@@ -13,6 +13,7 @@
import { sql } from './db.js';
import { solanaRpcEndpoints } from './solana/connection.js';
+import { fetchSafePublicUrlPinned } from './ssrf-guard.js';
import {
truncate,
resolveGateway,
@@ -29,6 +30,9 @@ import {
const MPL_AGENT_IDENTITY_PROGRAM = '1DREGFgysWYxLnRnKQnwrxnJQeSMk2HmGaC6whw2B2p';
const FETCH_TIMEOUT_MS = 6_000;
+// On-chain metadata JSON is small by convention; anything larger is not a
+// metadata document. Also the streaming cap the pinned guard enforces.
+const MAX_METADATA_BYTES = 1024 * 1024;
// Pick the best available mainnet RPC. solanaRpcEndpoints prefers Helius (which
// also answers DAS getAsset on the same URL), falling back to public nodes.
@@ -41,19 +45,24 @@ function mainnetRpc() {
async function fetchJsonWithTimeout(url, timeoutMs = FETCH_TIMEOUT_MS) {
const resolved = resolveGateway(url);
if (!resolved) return null;
- const ctrl = new AbortController();
- const t = setTimeout(() => ctrl.abort(), timeoutMs);
try {
- const r = await fetch(resolved, {
- signal: ctrl.signal,
- headers: { accept: 'application/json', 'user-agent': 'three.ws-onchain-indexer/1.0 (+https://three.ws)' },
- });
+ // metadataUri / json_uri values come from on-chain accounts anyone can
+ // register, i.e. attacker-controlled URLs. The pinned guard keeps the
+ // crawl from being turned into an SSRF against internal services from
+ // the Cloud Run network, and caps the body so a hostile host cannot
+ // stream unbounded bytes into the instance.
+ const r = await fetchSafePublicUrlPinned(
+ resolved,
+ {
+ signal: AbortSignal.timeout(timeoutMs),
+ headers: { accept: 'application/json', 'user-agent': 'three.ws-onchain-indexer/1.0 (+https://three.ws)' },
+ },
+ { maxBytes: MAX_METADATA_BYTES },
+ );
if (!r.ok) return null;
return await r.json();
} catch {
return null;
- } finally {
- clearTimeout(t);
}
}