fix: guard hook payload strings

This commit is contained in:
Peter Steinberger
2025-12-24 17:49:52 +01:00
parent 131a9aa1ac
commit b85503b3b2

View File

@@ -1363,10 +1363,8 @@ export async function startGatewayServer(
typeof body.value === "object" && body.value !== null ? body.value : {}; typeof body.value === "object" && body.value !== null ? body.value : {};
if (subPath === "wake") { if (subPath === "wake") {
const text = const textRaw = (payload as { text?: unknown }).text;
typeof (payload as { text?: unknown }).text === "string" const text = typeof textRaw === "string" ? textRaw.trim() : "";
? (payload as { text?: string }).text.trim()
: "";
if (!text) { if (!text) {
sendJson(res, 400, { ok: false, error: "text required" }); sendJson(res, 400, { ok: false, error: "text required" });
return true; return true;
@@ -1382,10 +1380,8 @@ export async function startGatewayServer(
} }
if (subPath === "agent") { if (subPath === "agent") {
const message = const messageRaw = (payload as { message?: unknown }).message;
typeof (payload as { message?: unknown }).message === "string" const message = typeof messageRaw === "string" ? messageRaw.trim() : "";
? (payload as { message?: string }).message.trim()
: "";
if (!message) { if (!message) {
sendJson(res, 400, { ok: false, error: "message required" }); sendJson(res, 400, { ok: false, error: "message required" });
return true; return true;
@@ -1486,7 +1482,7 @@ export async function startGatewayServer(
requestReplyHeartbeatNow({ reason: `hook:${jobId}` }); requestReplyHeartbeatNow({ reason: `hook:${jobId}` });
} }
} catch (err) { } catch (err) {
logHooks.warn({ err: String(err) }, "hook agent failed"); logHooks.warn("hook agent failed", { err: String(err) });
enqueueSystemEvent(`Hook ${name} (error): ${String(err)}`); enqueueSystemEvent(`Hook ${name} (error): ${String(err)}`);
if (wakeMode === "now") { if (wakeMode === "now") {
requestReplyHeartbeatNow({ reason: `hook:${jobId}:error` }); requestReplyHeartbeatNow({ reason: `hook:${jobId}:error` });