3D engine that AI agents drive
Fix dependency advisories and harden the MCP preview
Nguyen Xuan An3c8e8896b0b5
diff --git a/.github/dependabot.yml b/.github/dependabot.ymlnew file mode 100644index 00000000..418911ee--- /dev/null+++ b/.github/dependabot.yml@@ -0,0 +1,19 @@+version: 2+updates:+ - package-ecosystem: npm+ directory: /+ schedule:+ interval: weekly+ open-pull-requests-limit: 3+ groups:+ development:+ dependency-type: development+ - package-ecosystem: github-actions+ directory: /+ schedule:+ interval: weekly+ open-pull-requests-limit: 2+ groups:+ actions:+ patterns:+ - '*'diff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex 4d251311..246d69c6 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -22,6 +22,7 @@ jobs:package-manager-cache: false- run: npm install --global [email protected]- run: npm ci --ignore-scripts+ - run: npm audit --audit-level=high- run: npm run size- run: npm test- run: npm run prepare:releasediff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3124ebf6..0ac5fdef 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,9 @@## Unreleased+- Update the bundled `zod` to 4.6.7, which fixes a memory exhaustion advisory in the validation of oversized collections+- Make the MCP preview server reject requests with another Host header, which closes DNS rebinding+- Check the size of a mesh `array` before it allocates. Before this, the check ran after the copies existed- Change the bevel `profile` to the meaning it has in Blender: 0.5 is a circular arc, 0.25 is flat, 1 is square, and below 0.25 is concave. Before this, 0 was flat and 0.5 was a parabola, so a recipe with a `profile` other than 0.5 changes shape- Stop adding a fan of triangles where one beveled edge ends at a vertex with three faces. The third face now takes the profile's points, as in Blenderdiff --git a/SECURITY.md b/SECURITY.mdnew file mode 100644index 00000000..5d8616f5--- /dev/null+++ b/SECURITY.md@@ -0,0 +1,24 @@+# Security++## Report a problem++Email [email protected] with the steps to reproduce the problem. Do not open a public issue for a vulnerability.++## Supported versions++Only the latest published version of `@codepawlhq/67js` gets security fixes.++## What the MCP server protects++The MCP server takes input from AI agents, and that input can come from a prompt injection. The server must therefore hold these limits:++- It runs no code that a tool call supplies.+- It reads assets only from the configured catalog, and it fetches no remote URLs for assets.+- It writes render output only to the configured jobs folder.+- It bounds every collection, count and size before it allocates memory.++`docs/mcp.md` describes each limit and its boundary tests.++## Dependencies++The `Test` workflow runs `npm audit` on each pull request and fails on a high or critical advisory. `zod` and other packages count even when they are development dependencies, because the build bundles them into the MCP server. Dependabot opens grouped updates each week.diff --git a/package-lock.json b/package-lock.jsonindex a7bd1674..e0fd6e3a 100644--- a/package-lock.json+++ b/package-lock.json@@ -29,8 +29,8 @@"three": "0.186.1","three-mesh-bvh": "0.9.16","vite": "8.3.4",- "wrangler": "4.149.0",- "zod": "4.6.5"+ "wrangler": "4.156.0",+ "zod": "4.6.7"},"engines": {"node": ">=20.19.0"@@ -75,9 +75,9 @@}},"node_modules/@cloudflare/workerd-darwin-64": {- "version": "1.20261006.1",- "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20261006.1.tgz",- "integrity": "sha512-lCX6avJO2It9AyDEYitjmOtJRVp/xmaW0TziyoLAnfxlzozyyRbSFfIIMMCiDx/sTP1++E4VLbV+7BHSD33f0Q==",+ "version": "1.20261023.1",+ "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20261023.1.tgz",+ "integrity": "sha512-lsEx0i7nR0PNG/erUFFHmQmiidEhLfDE5uQmAL9421/y4/ycuxDDOSaxu3VGGYFFPK5sduyUeMmjIlX4CwOBFg==","cpu": ["x64"],@@ -92,9 +92,9 @@}},"node_modules/@cloudflare/workerd-darwin-arm64": {- "version": "1.20261006.1",- "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20261006.1.tgz",- "integrity": "sha512-PyFGjOaldtppnLuKsdkoYWXfLVpDjuf8u+uoykX+1Xvxo2EPmCVViq0iDKm+U7c7PRno85ehS3/MPVXyk2HwHw==",+ "version": "1.20261023.1",+ "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20261023.1.tgz",+ "integrity": "sha512-5e79fHgabdDD8EgmjOhJ1S+xMsf6DbC7fL7IgTBizMnzOp0P2isDn7pYmUxI9AJZE9FVQ4RUilH/I36YNg+GQQ==","cpu": ["arm64"],@@ -109,9 +109,9 @@}},"node_modules/@cloudflare/workerd-linux-64": {- "version": "1.20261006.1",- "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20261006.1.tgz",- "integrity": "sha512-Ntf9S8eesmVufdjaT2kzWlz6Ng9XGYTc6cHQVRKAg59lFufwsIabGeMT6U4KkrpEeSIxgHq8aPtuLbZXE19tCA==",+ "version": "1.20261023.1",+ "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20261023.1.tgz",+ "integrity": "sha512-VHQ6jKFSihjR2+x1buby8XTdBLLJztVnYiB7OLOTYO8aDXB+c1Rd2410PdgFuFYc4AgFEk6PCJLyCLL5L1KBnw==","cpu": ["x64"],@@ -126,9 +126,9 @@}},"node_modules/@cloudflare/workerd-linux-arm64": {- "version": "1.20261006.1",- "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20261006.1.tgz",- "integrity": "sha512-JyeDBymVWw5tVRebSsVE8ojDYxd6UlZrAseHU8G+NpIyd5wF61tXlF/axLeCUqu0pOhBFHb8I5QKi0jwrCK41Q==",+ "version": "1.20261023.1",+ "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20261023.1.tgz",+ "integrity": "sha512-ilpRHzfDN8YFRM5CLRKuFw40x/LJBS89yVdhdQmxehlVDuBqjKpJB++zPFbTgKRRFaNupgnXc8RHktXAIhgCmQ==","cpu": ["arm64"],@@ -143,9 +143,9 @@}},"node_modules/@cloudflare/workerd-windows-64": {- "version": "1.20261006.1",- "resolved": "https://registry.npmjs.org/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20261006.1.tgz",- "integrity": "sha512-nWP0URNqOBN9fa/gZ7eh/w051DwjOXN8j4lDZDYVXyQPsux6sV3DfyYZT+CjR/rt9nKBSmJT9QE9/bWT18+84w==",+ "version": "1.20261023.1",+ "resolved": "https://registry.npmjs.org/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20261023.1.tgz",+ "integrity": "sha512-279WLVjNsMycAwr0EZNiNEf0l2SY6NUtsN80NwZzbTHzakmiN+WSx4w38muxPm+PAU0oSPPAPXKVD+H6Hya8xw==","cpu": ["x64"],@@ -2736,16 +2736,16 @@}},"node_modules/miniflare": {- "version": "5.20261006.1-alpha",- "resolved": "https://registry.npmjs.org/miniflare/-/miniflare-5.20261006.1-alpha.tgz",- "integrity": "sha512-6ylv8tamkrspDI2R/cAYfv+YWmfGNdXe76Pi9TauEUWsFVXn3LNF9Yk8oduzf1a+TYsSRYTqlOE7+nGGRsMHdw==",+ "version": "5.20261023.3-beta",+ "resolved": "https://registry.npmjs.org/miniflare/-/miniflare-5.20261023.3-beta.tgz",+ "integrity": "sha512-thdXzlktu5GE1o/BlmMAPeJ0Cu6Tu5LpMbRlyfRrpVvMRrhd6p52TMqcITCZZLVzt1UO92VGBkLDhLOpryUAyQ==","dev": true,"license": "MIT","dependencies": {"@cspotcode/source-map-support": "0.8.1","sharp": "0.35.5",- "undici": "7.29.1",- "workerd": "1.20261006.1",+ "undici": "7.30.1",+ "workerd": "1.20261023.1","ws": "8.21.0","youch": "4.1.0-beta.10"},@@ -3265,9 +3265,9 @@"license": "0BSD"},"node_modules/undici": {- "version": "7.29.1",- "resolved": "https://registry.npmjs.org/undici/-/undici-7.29.1.tgz",- "integrity": "sha512-RYONW2MeafgYlkVOKYKkA/Ag7BmXqgIWCa8t1m0JcxrQg9pI9lEqRhAOruOBCbAohOa/gkCF+iPi9hrgvTzu6Q==",+ "version": "7.30.1",+ "resolved": "https://registry.npmjs.org/undici/-/undici-7.30.1.tgz",+ "integrity": "sha512-03KrMbjIFDWQR5RNPrSw3bd1r12JpyFQl9/yxjUbJtqkjmllqC5lFjZh6ujeuJCKr8EOQvRW872Oy/az+nLYxg==","dev": true,"license": "MIT","engines": {@@ -3431,9 +3431,9 @@}},"node_modules/workerd": {- "version": "1.20261006.1",- "resolved": "https://registry.npmjs.org/workerd/-/workerd-1.20261006.1.tgz",- "integrity": "sha512-8MadBuffZ5NdpLwZjUmsqT5QlaKXq4gjgT6wzcKeynZTICNXyePhc+5QVoKiK7+MMhFTLNrRO2KXLlpk8Q6BkA==",+ "version": "1.20261023.1",+ "resolved": "https://registry.npmjs.org/workerd/-/workerd-1.20261023.1.tgz",+ "integrity": "sha512-NeofJFyaYNpqKpFRJW3ApuonaerPd6/JWlfTtLDYf2A6ygqrDEFnYgEXmc0hhOxqnJsSM+kXJN6VebPojzRrsg==","dev": true,"hasInstallScript": true,"license": "Apache-2.0",@@ -3444,17 +3444,17 @@"node": ">=16"},"optionalDependencies": {- "@cloudflare/workerd-darwin-64": "1.20261006.1",- "@cloudflare/workerd-darwin-arm64": "1.20261006.1",- "@cloudflare/workerd-linux-64": "1.20261006.1",- "@cloudflare/workerd-linux-arm64": "1.20261006.1",- "@cloudflare/workerd-windows-64": "1.20261006.1"+ "@cloudflare/workerd-darwin-64": "1.20261023.1",+ "@cloudflare/workerd-darwin-arm64": "1.20261023.1",+ "@cloudflare/workerd-linux-64": "1.20261023.1",+ "@cloudflare/workerd-linux-arm64": "1.20261023.1",+ "@cloudflare/workerd-windows-64": "1.20261023.1"}},"node_modules/wrangler": {- "version": "4.149.0",- "resolved": "https://registry.npmjs.org/wrangler/-/wrangler-4.149.0.tgz",- "integrity": "sha512-OzK7xmB5r5iLKb3cIT3783g13fe6T7xyeKu9LEdUyl+DKAM2KP/jkjnE0OUhyw+mB/XJM9ycjgF3MWm8PR9amg==",+ "version": "4.156.0",+ "resolved": "https://registry.npmjs.org/wrangler/-/wrangler-4.156.0.tgz",+ "integrity": "sha512-kVLAShuLiNgE3jcrmXcymDf/iPKDPrSxACe5ueugW/33HeNB9E9CkKYchudCeBwgmsnl4k+1zt4NO7vqb/fRuQ==","dev": true,"license": "MIT OR Apache-2.0","dependencies": {@@ -3462,10 +3462,10 @@"@cloudflare/unenv-preset": "2.16.2","blake3-wasm": "2.1.5","esbuild": "0.28.2",- "miniflare": "5.20261006.1-alpha",+ "miniflare": "5.20261023.3-beta","path-to-regexp": "6.3.0","unenv": "2.0.0-rc.24",- "workerd": "1.20261006.1"+ "workerd": "1.20261023.1"},"bin": {"cf-wrangler": "bin/cf-wrangler.js",@@ -3479,7 +3479,7 @@"fsevents": "2.3.3"},"peerDependencies": {- "@cloudflare/workers-types": "^5.20261006.1"+ "@cloudflare/workers-types": "^5.20261023.1"},"peerDependenciesMeta": {"@cloudflare/workers-types": {@@ -3551,9 +3551,9 @@}},"node_modules/zod": {- "version": "4.6.5",- "resolved": "https://registry.npmjs.org/zod/-/zod-4.6.5.tgz",- "integrity": "sha512-v5l/aFXZQeai4awLbOpSoHecE9UiMrnfx75tEXLjNonXVARxQ5mOeipTjROUchszUNCqnE+hqAMujRsRHsut2Q==",+ "version": "4.6.7",+ "resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz",+ "integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==","dev": true,"license": "MIT","funding": {diff --git a/package.json b/package.jsonindex 13020750..6f5aed6d 100644--- a/package.json+++ b/package.json@@ -164,7 +164,7 @@"three": "0.186.1","three-mesh-bvh": "0.9.16","vite": "8.3.4",- "wrangler": "4.149.0",- "zod": "4.6.5"+ "wrangler": "4.156.0",+ "zod": "4.6.7"}}diff --git a/scripts/agent-runtime.mjs b/scripts/agent-runtime.mjsindex 14ef078b..ad12dfae 100644--- a/scripts/agent-runtime.mjs+++ b/scripts/agent-runtime.mjs@@ -9,6 +9,7 @@ import { AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS } from '../src/ageimport { createAgentAssetCatalog } from './agent-asset-catalog.mjs';import { createAgentRenderJobs } from './agent-render-jobs.mjs';import { createFrameEncoder } from './frame-encoder.mjs';+import { isPreviewHost } from './preview-host.mjs';import { normalizeReview, REVIEW_LIMITS } from './agent-review.mjs';const SCENE_LIMITS = AGENT_SCENE_DEFAULT_LIMITS;@@ -142,6 +143,11 @@ export function createAgentRuntime({ backend = 'gpu', browser: browserPath, memoreadFile(previewUrl, 'utf8'),]);httpServer = createServer((request, response) => {+ if (!isPreviewHost(request.headers.host, httpServer.address().port)) {+ response.writeHead(403);+ response.end();+ return;+ }response.setHeader('Cache-Control', 'no-store');response.setHeader('Content-Security-Policy', "default-src 'none'; script-src 'self' 'wasm-unsafe-eval'; style-src 'unsafe-inline'; img-src data: blob:; connect-src 'self' blob:");const vendor = request.method === 'GET' ? MANIFOLD_FILES[request.url] : undefined;diff --git a/scripts/preview-host.mjs b/scripts/preview-host.mjsnew file mode 100644index 00000000..e55c8fed--- /dev/null+++ b/scripts/preview-host.mjs@@ -0,0 +1,4 @@+// The preview listens on loopback, and a web page can still reach it through DNS rebinding. The Host header gives that away.+export function isPreviewHost(host, port) {+ return host === `127.0.0.1:${port}`;+}diff --git a/src/mesh-recipe.js b/src/mesh-recipe.jsindex c64b3e99..9c047270 100644--- a/src/mesh-recipe.js+++ b/src/mesh-recipe.js@@ -167,6 +167,16 @@ export function normalizeMeshEdits(edits) {});}+// An array multiplies a mesh in one step, so its size must be known before it allocates.+function checkArrayBudget(mesh, edit, limits, index) {+ if (edit.op !== 'array') return;+ const vertices = mesh.vertexCount * edit.count;+ const faces = mesh.faceCount * edit.count;+ if (vertices > limits.maxVertices || faces > limits.maxFaces) {+ throw new RangeError(`Mesh edit ${index} (array) would make ${vertices} vertices and ${faces} faces, over the limit of ${limits.maxVertices} vertices and ${limits.maxFaces} faces. Lower count, or use a simpler mesh.`);+ }+}+function checkBudget(mesh, limits, index, op) {if (mesh.vertexCount > limits.maxVertices || mesh.faceCount > limits.maxFaces) {throw new RangeError(`Mesh edit ${index} (${op}) grows the mesh to ${mesh.vertexCount} vertices and ${mesh.faceCount} faces, over the limit of ${limits.maxVertices} vertices or ${limits.maxFaces} faces.`);@@ -347,6 +357,7 @@ export function applyMeshEdits(mesh, edits, { maxVertices = 250_000, maxFaces =const results = [];let current = mesh;normalized.forEach((edit, index) => {+ checkArrayBudget(current, edit, limits, index);const outcome = runEdit(current, edit, index, { resolveCutter });current = outcome.mesh;checkBudget(current, limits, index, edit.op);@@ -390,6 +401,7 @@ export function evaluateMeshStack(mesh, stack, { maxVertices = 250_000, maxFacescurrent = hit.mesh;result = { ...hit.result, cached: true };} else {+ checkArrayBudget(current, node, limits, index);const outcome = runEdit(current, node, index, {});current = outcome.mesh;checkBudget(current, limits, index, node.op);diff --git a/tests/agent-runtime.test.js b/tests/agent-runtime.test.jsindex 6a124ad3..387d23b5 100644--- a/tests/agent-runtime.test.js+++ b/tests/agent-runtime.test.js@@ -1,6 +1,7 @@import test from 'node:test';import assert from 'node:assert/strict';import { createAgentRuntime } from '../scripts/agent-runtime.mjs';+import { isPreviewHost } from '../scripts/preview-host.mjs';import { readFile } from 'node:fs/promises';import { createServer } from 'node:http';import { randomUUID } from 'node:crypto';@@ -95,7 +96,7 @@ async function reviewRuntimeHarness({ failShot, blockShot = false, oversize = faconst context = createContext({ createServer, randomUUID, existsSync: () => true,readFile: async () => '', packageMetadata: { version: 'test' },createRequire: () => ({ resolve: () => { throw new Error('no peer in tests'); } }),- AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, normalizeReview, REVIEW_LIMITS,+ AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, normalizeReview, REVIEW_LIMITS, isPreviewHost,chromium: { launch: async () => browser }, URL, Buffer, process, performance, setTimeout, clearTimeout,});new Script(`${source}\nglobalThis.runtime = createAgentRuntime({ backend: 'cpu' });`).runInContext(context);@@ -260,3 +261,11 @@ test('requests cannot address an absent session or enter a closing runtime', asyawait assert.rejects(runtime.checkpoint({ sessionId: 'missing' }), /closing|closed/);await closing;});++test('the preview server accepts only its own loopback host', () => {+ assert.equal(isPreviewHost('127.0.0.1:4100', 4100), true);+ assert.equal(isPreviewHost('evil.example:4100', 4100), false);+ assert.equal(isPreviewHost('localhost:4100', 4100), false);+ assert.equal(isPreviewHost('127.0.0.1:4101', 4100), false);+ assert.equal(isPreviewHost(undefined, 4100), false);+});diff --git a/tests/mesh-stack.test.js b/tests/mesh-stack.test.jsindex 2713bc62..a5ae222b 100644--- a/tests/mesh-stack.test.js+++ b/tests/mesh-stack.test.js@@ -138,3 +138,9 @@ test('recipe meshes evaluate stacks, reuse cached prefixes and apply nodes intoassert.throws(() => scene.apply([{ type: 'set-mesh-stack', geometry: 'wing', stack: [{ op: 'translate', offset: [0, 1, 0] }] }], { expectedRevision: 2 }), /op must be one of mirror/);assert.equal(scene.revision, 2);});++test('an array over the budget fails before it allocates, and names the fix', () => {+ const edits = [{ op: 'array', count: 200 }];+ assert.throws(() => applyMeshEdits(cube(), edits, { maxVertices: 100, maxFaces: 100 }), /would make 1600 vertices .* Lower count/);+ assert.throws(() => evaluateMeshStack(cube(), edits, { maxVertices: 100, maxFaces: 100 }), /would make 1600 vertices/);+});