Skip to content

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.

security(admin): scrub the removed admin console from cron hints, healthz alert routing, and its CSRF tests

nirholas7c09c09a6a1a
diff --git a/api/cron/avaturn-seed-cron.js b/api/cron/avaturn-seed-cron.js
index 8441b16b5..59ab3d5de 100644
--- a/api/cron/avaturn-seed-cron.js
+++ b/api/cron/avaturn-seed-cron.js
@@ -259,15 +259,15 @@ export default wrapCron(async (req, res) => {
if (!method(req, res, ['GET'])) return;
if (!requireCron(req, res)) return;
- // DB flag is the live control (flip it from the admin console with no
- // redeploy); the AVATURN_SEED_ENABLED env var is the fallback default used
- // only when no app_flags row exists yet, preserving the prior behavior.
+ // DB flag is the live control (flip the app_flags row with no redeploy);
+ // the AVATURN_SEED_ENABLED env var is the fallback default used only when
+ // no app_flags row exists yet, preserving the prior behavior.
const enabled = await isFlagEnabled('avaturn_seed', { fallback: env.AVATURN_SEED_ENABLED });
if (!enabled) {
return json(res, 200, {
ok: true,
skipped: 'disabled',
- hint: 'enable instantly via POST /api/admin/flags { "key":"avaturn_seed","enabled":true } (or set AVATURN_SEED_ENABLED=1)',
+ hint: 'enable by setting the avaturn_seed row in the app_flags table (or set AVATURN_SEED_ENABLED=1)',
});
}
diff --git a/api/healthz.js b/api/healthz.js
index a9ad4df28..b9b7ca862 100644
--- a/api/healthz.js
+++ b/api/healthz.js
@@ -250,8 +250,8 @@ async function probeX402() {
// Self-facilitator verify/settle outcomes (last 24h), grouped by reason
// class. A paying buyer whose wallet mutates the prepared transaction gets a
// deterministic verify 402 with everything else on this endpoint green —
- // without this block that failure mode is invisible outside the admin
- // dashboards. Only the reason prefix (before ':') is exposed: suffixes can
+ // without this block that failure mode is invisible outside the raw
+ // facilitator log. Only the reason prefix (before ':') is exposed: suffixes can
// carry wallet addresses, the prefix is a fixed validator code.
try {
const { sql } = await import('./_lib/db.js');
@@ -362,12 +362,12 @@ export default wrap(async (req, res) => {
},
},
// Ops alerts (api/_lib/alerts.js). Every sendOpsAlert() ALWAYS persists to
- // the ops_alerts table and surfaces on the admin dashboard (/admin/ops), so
- // alerts are never silently dropped. Telegram is an OPTIONAL extra push for
- // real-time notification; its absence is expected, not a fault.
+ // the ops_alerts table, so alerts are never silently dropped; read them via
+ // the ops-secret-gated /api/ops/health surface. Telegram is an OPTIONAL
+ // extra push for real-time notification; its absence is expected, not a fault.
alerts: {
- primary: 'dashboard',
- dashboard: '/admin/ops',
+ primary: 'ops_alerts',
+ read_via: '/api/ops/health',
telegram_push: alertsConfigured() ? 'enabled' : 'disabled',
telegram_requires: ['TELEGRAM_BOT_TOKEN', 'TELEGRAM_ALERTS_CHAT_ID'],
},
diff --git a/tests/api/healthz.test.js b/tests/api/healthz.test.js
index 400875b20..29354f32b 100644
--- a/tests/api/healthz.test.js
+++ b/tests/api/healthz.test.js
@@ -63,10 +63,10 @@ describe('GET /api/healthz', () => {
expect(body.monitor.running).toBe(true);
});
- // Ops alerts always persist to the dashboard (ops_alerts / /admin/ops); the
- // dashboard is the primary sink and is never a no-op. Telegram is an optional
- // extra push. healthz reports the dashboard as primary and telegram_push as
- // enabled/disabled — a disabled push is expected, not a fault.
+ // Ops alerts always persist to the ops_alerts table; the table is the primary
+ // sink and is never a no-op. Telegram is an optional extra push. healthz
+ // reports ops_alerts as primary and telegram_push as enabled/disabled; a
+ // disabled push is expected, not a fault.
describe('ops alert channel', () => {
const SAVED = [process.env.TELEGRAM_BOT_TOKEN, process.env.TELEGRAM_ALERTS_CHAT_ID];
afterEach(() => {
@@ -76,12 +76,12 @@ describe('GET /api/healthz', () => {
}
});
- it('always reports the dashboard as the primary sink', async () => {
+ it('always reports the ops_alerts table as the primary sink', async () => {
delete process.env.TELEGRAM_BOT_TOKEN;
delete process.env.TELEGRAM_ALERTS_CHAT_ID;
const { body } = await callHealthz();
- expect(body.alerts.primary).toBe('dashboard');
- expect(body.alerts.dashboard).toBe('/admin/ops');
+ expect(body.alerts.primary).toBe('ops_alerts');
+ expect(body.alerts.read_via).toBe('/api/ops/health');
// No "silent no-op" framing — alerts persist regardless of Telegram.
expect(body.alerts.warning).toBeUndefined();
});
diff --git a/tests/api/security-csrf-gates.test.js b/tests/api/security-csrf-gates.test.js
index d9464cde9..0679441e1 100644
--- a/tests/api/security-csrf-gates.test.js
+++ b/tests/api/security-csrf-gates.test.js
@@ -173,9 +173,6 @@ vi.mock('../../api/_lib/r2.js', () => ({
const { default: agentsRoot, handleGetOne, handleWallet } = await import('../../api/agents.js');
const { default: keysHandler } = await import('../../api/keys/index.js');
const { default: keyByIdHandler } = await import('../../api/keys/[id].js');
-const { default: adminUserHandler } = await import('../../api/admin/user/[id].js');
-const { default: adminWithdrawalsHandler } = await import('../../api/admin/withdrawals/[id].js');
-const { default: adminRiderPassesHandler } = await import('../../api/admin/rider-passes.js');
const { default: agentActionsHandler } = await import('../../api/agent-actions.js');
const { default: agentMemoryHandler } = await import('../../api/agent-memory.js');
const { default: subscriptionsHandler } = await import('../../api/subscriptions.js');
@@ -419,99 +416,6 @@ describe('POST/DELETE /api/agents/:id/wallet — CSRF gate', () => {
});
});
-// ── /api/admin/user/:id ───────────────────────────────────────────────────
-
-describe('PATCH /api/admin/user/:id — CSRF gate', () => {
- it('rejects PATCH without CSRF (admin auth alone is not enough)', async () => {
- authState.session = { id: 'admin-1', is_admin: true };
- const req = makeReq({
- method: 'PATCH',
- url: '/api/admin/user/abc',
- body: { plan: 'pro' },
- });
- const res = makeRes();
- await adminUserHandler(req, res);
- expect(res.statusCode).toBe(403);
- expect(parseRes(res).error).toBe('csrf_missing');
- });
-
- it('proceeds when a valid CSRF token is presented', async () => {
- const userId = '11111111-2222-4333-8444-555555555555';
- authState.session = { id: 'admin-1', is_admin: true };
- const token = issueCsrfFor('admin-1');
- sqlState.queue.push([
- { id: userId, email: '[email protected]', plan: 'pro', is_admin: false, deleted_at: null },
- ]);
- const req = makeReq({
- method: 'PATCH',
- url: `/api/admin/user/${userId}`,
- headers: { 'x-csrf-token': token },
- body: { plan: 'pro' },
- });
- const res = makeRes();
- await adminUserHandler(req, res);
- expect(res.statusCode).toBe(200);
- expect(parseRes(res).user.id).toBe(userId);
- });
-});
-
-// ── /api/admin/withdrawals/:id ────────────────────────────────────────────
-
-describe('PATCH /api/admin/withdrawals/:id — CSRF gate', () => {
- it('rejects PATCH without CSRF', async () => {
- authState.session = { id: 'admin-2', is_admin: true };
- const req = makeReq({
- method: 'PATCH',
- url: '/api/admin/withdrawals/w1',
- query: { id: 'w1' },
- body: { status: 'processing', tx_signature: 'tx-123' },
- });
- const res = makeRes();
- await adminWithdrawalsHandler(req, res);
- expect(res.statusCode).toBe(403);
- expect(parseRes(res).error).toBe('csrf_missing');
- });
-});
-
-// ── /api/admin/rider-passes ───────────────────────────────────────────────
-
-describe('POST/DELETE /api/admin/rider-passes — CSRF gate', () => {
- it('POST rejects without CSRF', async () => {
- authState.session = { id: 'admin-3', is_admin: true };
- const req = makeReq({
- method: 'POST',
- url: '/api/admin/rider-passes',
- body: { wallet_address: '0xabc' },
- });
- const res = makeRes();
- await adminRiderPassesHandler(req, res);
- expect(res.statusCode).toBe(403);
- expect(parseRes(res).error).toBe('csrf_missing');
- });
-
- it('DELETE rejects without CSRF', async () => {
- authState.session = { id: 'admin-3', is_admin: true };
- const req = makeReq({
- method: 'DELETE',
- url: '/api/admin/rider-passes',
- body: { wallet_address: '0xabc' },
- });
- const res = makeRes();
- await adminRiderPassesHandler(req, res);
- expect(res.statusCode).toBe(403);
- expect(parseRes(res).error).toBe('csrf_missing');
- });
-
- it('GET is not gated (read-only)', async () => {
- authState.session = { id: 'admin-3', is_admin: true };
- sqlState.queue.push([]);
- const req = makeReq({ method: 'GET', url: '/api/admin/rider-passes' });
- const res = makeRes();
- await adminRiderPassesHandler(req, res);
- expect(res.statusCode).toBe(200);
- });
-});
-
// ── /api/agents (root) — creation is CSRF-gated like its sibling mutations ─
describe('POST /api/agents — CSRF gate on creation', () => {