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
security(swarms): require CSRF and a write budget on every swarm mutation
nirholas46b80bee75dd
diff --git a/api/_lib/rate-limit.js b/api/_lib/rate-limit.jsindex 8968d1585..551fcabd8 100644--- a/api/_lib/rate-limit.js+++ b/api/_lib/rate-limit.js@@ -1494,6 +1494,14 @@ export const limits = {// Redis outage fails closed rather than uncapping custodial spends.tradePerUser: (userId) =>getLimiter('agent-trade:user', { limit: 30, window: '1 m', critical: true }).limit(userId),+ // Trading-swarm mutations (POST /api/swarms): contribute/exit move real SOL out+ // of a custodial wallet and kill/pause change a live treasury's mandate. Same+ // class as an agent trade, so it gets the same 30/min per-user write budget in+ // its own bucket (an owner actively trading must not 429 their swarm actions,+ // and vice versa). Critical: a Redis outage fails closed rather than uncapping+ // custodial spends.+ swarmMutate: (userId) =>+ getLimiter('swarm:mutate:user', { limit: 30, window: '1 m', critical: true }).limit(userId),// Per-user audit-log reads — the page polls on mount + "load older". 120/min// per user is generous for browse but discourages scraping the full year.// local: per-user browse/poll of one's own audit log — no side effects, nodiff --git a/api/swarms/index.js b/api/swarms/index.jsindex 59cbda48e..8ae30898b 100644--- a/api/swarms/index.js+++ b/api/swarms/index.js@@ -7,10 +7,20 @@// Every mutation that moves SOL (contribute, exit) executes a real on-chain// transfer inside the lib, spend-guarded and audited. The treasury balance always// ties to chain — there are no virtual balances here.+//+// Because those mutations move real funds from a custodial wallet, every POST+// carries the same two guards the rest of the platform's money writes do+// (security review L3): a CSRF token when the caller is a cookie session, so a+// third-party page can never spend on a signed-in visitor's behalf, and a+// per-user write budget so a hijacked session or runaway client can't fire an+// unbounded stream of contributes. Bearer/API-key callers are CSRF-exempt by+// construction (the token is the intent) and still metered.-import { cors, method, json, error, wrap, readJson } from '../_lib/http.js';+import { cors, method, json, error, wrap, readJson, rateLimited } from '../_lib/http.js';import { parseLimit, parseOffset } from '../_lib/http-params.js';import { resolveAccount } from '../_lib/account-auth.js';+import { requireCsrf } from '../_lib/csrf.js';+import { limits } from '../_lib/rate-limit.js';import {createSwarm, joinSwarm, contributeToSwarm, exitSwarm, killSwarm,setSwarmPaused, listSwarms, listSwarmsForUser, SwarmError,@@ -48,9 +58,12 @@ export default wrap(async (req, res) => {return json(res, 200, { data });}- // POST — all mutations require auth.+ // POST — all mutations require auth, CSRF (session callers), and a budget.const auth = await resolveAccount(req, res);if (!auth) return error(res, 401, 'unauthorized', 'sign in required');+ if (!(await requireCsrf(req, res, auth.userId))) return;+ const rl = await limits.swarmMutate(auth.userId);+ if (!rl.success) return rateLimited(res, rl, 'too many swarm actions — slow down');const body = await readJson(req).catch(() => ({}));const action = String(body.action || '');