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.

fix(fleet-console): compare the scan token in constant time

nirholas37e8b45e7a21
diff --git a/services/fleet-console/src/server.js b/services/fleet-console/src/server.js
index 41721e289..16b290e30 100644
--- a/services/fleet-console/src/server.js
+++ b/services/fleet-console/src/server.js
@@ -18,6 +18,7 @@
*/
import { createServer } from 'node:http';
+import { createHash, timingSafeEqual } from 'node:crypto';
import { config } from './config.js';
import { runScan, progress } from './scan.js';
import * as store from './store.js';
@@ -26,6 +27,11 @@ import { repoPage, notFoundPage } from './views/repo.js';
import { docsPage } from './views/docs.js';
import { repoBadge, deploymentBadge, fleetBadge } from './badge.js';
+// Constant-time token check: hashing both sides first gives equal-length
+// buffers, so neither the content nor the length leaks through timing.
+const digest = (value) => createHash('sha256').update(String(value)).digest();
+const tokenMatches = (supplied, expected) => Boolean(supplied) && timingSafeEqual(digest(supplied), digest(expected));
+
const send = (res, status, body, headers = {}) => {
res.writeHead(status, {
'content-length': Buffer.byteLength(body),
@@ -120,7 +126,7 @@ const handler = async (req, res) => {
if (req.method !== 'POST') return json(res, 405, { error: 'use POST' }, { maxAge: 0 });
if (!config.scanToken) return json(res, 403, { error: 'FLEET_SCAN_TOKEN is not configured, so on-demand scans are disabled' }, { maxAge: 0 });
const supplied = req.headers.authorization?.replace(/^Bearer\s+/i, '') || url.searchParams.get('token') || '';
- if (supplied !== config.scanToken) return json(res, 401, { error: 'bad token' }, { maxAge: 0 });
+ if (!tokenMatches(supplied, config.scanToken)) return json(res, 401, { error: 'bad token' }, { maxAge: 0 });
if (progress.running) return json(res, 409, { error: 'a scan is already running', progress }, { maxAge: 0 });
triggerScan('on demand');
return json(res, 202, { started: true, progress }, { maxAge: 0 });