From 97302af836273617716881d8ff4be9c19bc9a34c Mon Sep 17 00:00:00 2001 From: redshift <213178690+1ftredsh@users.noreply.github.com> Date: Tue, 28 Apr 2026 14:48:59 +0530 Subject: [PATCH] feat(daemon): make client id required in /clients/add endpoint --- src/daemon/http/index.ts | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/daemon/http/index.ts b/src/daemon/http/index.ts index 4ecbbb4..767dc09 100644 --- a/src/daemon/http/index.ts +++ b/src/daemon/http/index.ts @@ -750,6 +750,7 @@ export function createDaemonRequestHandler(deps: { const bodyText = await readBody(req); const body = bodyText ? JSON.parse(bodyText) : {}; const name = body.name as string | undefined; + const explicitId = body.id as string | undefined; if (!name || typeof name !== "string" || name.trim() === "") { res.writeHead(400, { "Content-Type": "application/json" }); @@ -762,17 +763,31 @@ export function createDaemonRequestHandler(deps: { return; } - const clientId = name - .toLowerCase() - .replace(/\s+/g, "-") - .replace(/[^a-z0-9-]/g, ""); + if (!explicitId || typeof explicitId !== "string" || explicitId.trim() === "") { + res.writeHead(400, { "Content-Type": "application/json" }); + res.end( + JSON.stringify({ + error: + "Missing required 'id' field (must be a non-empty string).", + }), + ); + return; + } + + const sanitizeId = (value: string) => + value + .toLowerCase() + .replace(/\s+/g, "-") + .replace(/[^a-z0-9-]/g, ""); + + const clientId = sanitizeId(explicitId); if (!clientId) { res.writeHead(400, { "Content-Type": "application/json" }); res.end( JSON.stringify({ error: - "Invalid client name. Must contain alphanumeric characters.", + "Invalid client id. Must contain alphanumeric characters.", }), ); return;