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(uploads): reject inherited object keys as presign content types
nirholasaab4241d994b
diff --git a/api/motion-swap.js b/api/motion-swap.jsindex fc275d18e..3eee00c32 100644--- a/api/motion-swap.js+++ b/api/motion-swap.js@@ -75,7 +75,9 @@ async function presignVideo(req, res, body) {const contentType =typeof body?.content_type === 'string' ? body.content_type.trim().toLowerCase() : '';- const ext = VIDEO_CONTENT_TYPE_EXT[contentType];+ const ext = Object.hasOwn(VIDEO_CONTENT_TYPE_EXT, contentType)+ ? VIDEO_CONTENT_TYPE_EXT[contentType]+ : null;if (!ext) {return json(res, 400, {error: 'invalid_content_type',diff --git a/api/scene-glb-upload.js b/api/scene-glb-upload.jsindex 2c2165285..72137dd47 100644--- a/api/scene-glb-upload.js+++ b/api/scene-glb-upload.js@@ -70,7 +70,7 @@ export default wrap(async (req, res) => {const contentType =typeof body?.content_type === 'string' ? body.content_type.trim().toLowerCase() : '';- const ext = CONTENT_TYPE_EXT[contentType];+ const ext = Object.hasOwn(CONTENT_TYPE_EXT, contentType) ? CONTENT_TYPE_EXT[contentType] : null;if (!ext) {return json(res, 400, {error: 'invalid_content_type',diff --git a/api/scene-upload.js b/api/scene-upload.jsindex f85fb245b..27763dde1 100644--- a/api/scene-upload.js+++ b/api/scene-upload.js@@ -68,7 +68,7 @@ export default wrap(async (req, res) => {const contentType =typeof body?.content_type === 'string' ? body.content_type.trim().toLowerCase() : '';- const ext = CONTENT_TYPE_EXT[contentType];+ const ext = Object.hasOwn(CONTENT_TYPE_EXT, contentType) ? CONTENT_TYPE_EXT[contentType] : null;if (!ext) {return json(res, 400, {error: 'invalid_content_type',diff --git a/tests/upload-presign-content-type.test.js b/tests/upload-presign-content-type.test.jsnew file mode 100644index 000000000..ed83d9ba6--- /dev/null+++ b/tests/upload-presign-content-type.test.js@@ -0,0 +1,53 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';++const presign = vi.fn(async ({ key }) => `https://r2.example/${key}?sig=1`);+vi.mock('../api/_lib/r2.js', () => ({+ presignUpload: presign,+ publicUrl: (k) => `https://cdn.example/${k}`,+ objectStorageUsable: async () => ({ ok: true }),+}));+vi.mock('../api/_lib/rate-limit.js', () => ({+ limits: new Proxy({}, { get: () => async () => ({ success: true, reset: Date.now() + 1000 }) }),+ clientIp: () => '127.0.0.1',+}));++for (const [name, path, extra] of [+ ['scene-upload', '../api/scene-upload.js', {}],+ ['scene-glb-upload', '../api/scene-glb-upload.js', {}],+ ['motion-swap upload', '../api/motion-swap.js', { action: 'upload' }],+]) {+ describe(`${name} content_type allowlist`, () => {+ beforeEach(() => {+ presign.mockClear();+ Object.assign(process.env, {+ S3_ENDPOINT: 'https://r2.example',+ S3_BUCKET: 'b',+ S3_PUBLIC_DOMAIN: 'https://cdn.example',+ S3_ACCESS_KEY_ID: 'k',+ S3_SECRET_ACCESS_KEY: 's',+ });+ });+ for (const ct of ['constructor', 'tostring', '__proto__', 'hasownproperty', 'valueof']) {+ it(`rejects inherited property name "${ct}"`, async () => {+ const handler = (await import(path)).default;+ const req = {+ method: 'POST',+ url: '/x',+ headers: { 'content-type': 'application/json', origin: 'https://three.ws' },+ body: { ...extra, content_type: ct, size_bytes: 10 },+ };+ const res = {+ statusCode: 200,+ headers: {},+ setHeader(k, v) { this.headers[k] = v; },+ getHeader(k) { return this.headers[k]; },+ writeHead(c) { this.statusCode = c; },+ end(b) { this.payload = b; },+ };+ await handler(req, res);+ expect(res.statusCode).toBe(400);+ expect(presign).not.toHaveBeenCalled();+ });+ }+ });+}