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(og): fetch a profile portrait through the SSRF guard
nirholas34ef41a64ff7
diff --git a/api/_lib/og-avatar.js b/api/_lib/og-avatar.jsindex 1af873312..c7b9ae3f6 100644--- a/api/_lib/og-avatar.js+++ b/api/_lib/og-avatar.js@@ -17,8 +17,16 @@** It never throws. A dead host, a timeout, an HTML error page, or an oversized* body all return null, which every caller already renders as a monogram.+ *+ * The fetch goes through the pinned SSRF guard (api/_lib/ssrf-guard.js): a URL+ * that resolves to a private, loopback or metadata address, or redirects to one,+ * is refused, because the bytes come back to whoever requested the card. Coin+ * logos on the OG cards route through here too, and those URLs are chosen by+ * whoever launched the coin.*/+import { fetchSafePublicUrlPinned } from './ssrf-guard.js';+/** A portrait that does not fit in 1.5 MB is not a portrait we want to inline. */export const MAX_OG_IMAGE_BYTES = 1_500_000;@@ -39,7 +47,14 @@ export async function fetchOgImage(url, opts = {}) {if (typeof url !== 'string' || !/^https?:\/\//i.test(url)) return null;try {- const resp = await fetch(url, { signal: AbortSignal.timeout(timeoutMs) });+ // Pinned: the socket connects to the address that was validated, so a+ // rebinding DNS answer cannot swap in an internal host between check and+ // connect. maxBytes caps the stream inside the guard as well.+ const resp = await fetchSafePublicUrlPinned(+ url,+ { signal: AbortSignal.timeout(timeoutMs) },+ { allowHttp: true, maxBytes },+ );if (!resp.ok) return null;// The type lands inside an SVG `href="data:<ct>;base64,..."` attribute,diff --git a/tests/og-avatar.test.js b/tests/og-avatar.test.jsindex c81bdb6e6..0d1f71828 100644--- a/tests/og-avatar.test.js+++ b/tests/og-avatar.test.js@@ -1,5 +1,11 @@import { describe, it, expect, afterEach, vi } from 'vitest';+// The SSRF guard resolves DNS before fetching; route it straight to the stubbed+// global fetch so these cases stay offline. The guard is tested on its own.+vi.mock('../api/_lib/ssrf-guard.js', () => ({+ fetchSafePublicUrlPinned: (url, init) => globalThis.fetch(url, init),+}));+import { fetchOgImage, MAX_OG_IMAGE_BYTES } from '../api/_lib/og-avatar.js';import { parseLimit } from '../api/trending.js';