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(img): serve proxied SVGs under a sandboxed, script-free policy
nirholasf8e6602e428b
diff --git a/api/img.js b/api/img.jsindex 78f20f82b..6ae415907 100644--- a/api/img.js+++ b/api/img.js@@ -282,9 +282,18 @@ async function resolveImageFromMeta(metaUri, timeoutMs = META_TIMEOUT_MS) {}}+// Whatever this endpoint returns is a remote party's bytes served from the+// three.ws origin. Token art is routinely SVG, and an SVG opened as a top-level+// document runs its own <script> under this origin, so `?url=` pointed at a+// hostile SVG was script execution on three.ws. As an <img> or a texture the+// bytes render exactly as before; opened directly, `sandbox` puts the document+// in an opaque origin with scripts disabled.+const PROXIED_CSP = "default-src 'none'; img-src data:; style-src 'unsafe-inline'; sandbox";+export default wrap(async function handler(req, res) {if (cors(req, res, { methods: 'GET,OPTIONS', credentials: false })) return;if (!method(req, res, ['GET'])) return;+ res.setHeader('content-security-policy', PROXIED_CSP);const ip = clientIp(req);const rl = await limits.imgProxyIp(ip);diff --git a/tests/api-img-proxy.test.js b/tests/api-img-proxy.test.jsindex 4d0f9ae2b..3035ab2eb 100644--- a/tests/api-img-proxy.test.js+++ b/tests/api-img-proxy.test.js@@ -289,3 +289,31 @@ describe('api/img ?url= metadata follow', () => {expect([...res.body]).toEqual([3]);});});++describe('api/img same-origin document safety', () => {+ const SVG = 'https://evil.example/art.svg';++ it('serves a proxied SVG under a sandboxed, script-free policy', async () => {+ fetchModel.mockImplementation(async (url) => ({+ bytes: new TextEncoder().encode('<svg xmlns="http://www.w3.org/2000/svg"><script>alert(document.domain)</script></svg>'),+ url,+ contentType: 'image/svg+xml',+ filename: 'art.svg',+ }));++ const res = mockRes();+ await handler(mockReq(`?url=${encodeURIComponent(SVG)}&seed=SVG`), res);++ expect(res.headers['content-type']).toBe('image/svg+xml');+ const csp = res.headers['content-security-policy'];+ expect(csp).toContain('sandbox');+ expect(csp).toContain("default-src 'none'");+ expect(csp).not.toContain('script-src');+ });++ it('applies the same policy to the placeholder', async () => {+ const res = mockRes();+ await handler(mockReq('?seed=PLACEHOLDER'), res);+ expect(res.headers['content-security-policy']).toContain('sandbox');+ });+});