From 820f45e474f9f18634b10af4c6c67926974c72e6 Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Mon, 16 Nov 2026 14:05:46 -0600 Subject: [PATCH] fix(webui): triage final review, a reply names only a message id the host issued: the relay keeps in_reply_to only when it is an owner message id and drops anything else, so no model-written string reaches the transcript or the GET unchecked; the text cleaner also removes U+061C, U+180E, U+2028, U+2029 and U+FEFF (#1873, lane triage-host) --- packages/webui/src/triage-cards.mjs | 2 +- packages/webui/src/triage-host.mjs | 5 ++++- packages/webui/tests/triage-cards.test.mjs | 1 + packages/webui/tests/triage-host.test.mjs | 18 ++++++++++++------ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/webui/src/triage-cards.mjs b/packages/webui/src/triage-cards.mjs index 1233cf4af..76406ed53 100644 --- a/packages/webui/src/triage-cards.mjs +++ b/packages/webui/src/triage-cards.mjs @@ -23,7 +23,7 @@ const FENCE = /```cards[ \t]*\r?\n([\s\S]*?)\r?\n?```/g; export function plainText(value, max = MAX_TEXT) { if (typeof value !== "string") return ""; // eslint-disable-next-line no-control-regex - return value.replace(/\r\n?/g, "\n").replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f​-‏‪-‮⁦-⁩]/g, "").slice(0, max); + return value.replace(/\r\n?/g, "\n").replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u061c\u180e\u2028\u2029\ufeff​-‏‪-‮⁦-⁩]/g, "").slice(0, max); } // One card, or null. orgIds is the set of registry ids the snapshot read. diff --git a/packages/webui/src/triage-host.mjs b/packages/webui/src/triage-host.mjs index c691818e6..9927ca053 100644 --- a/packages/webui/src/triage-host.mjs +++ b/packages/webui/src/triage-host.mjs @@ -47,6 +47,8 @@ export const NOT_TAKEN = "Triage stopped before it read this message. Send it ag export const CAP_HOLD_MAX_MS = 48 * 3600 * 1000; const ISO_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z$/; const LINE_MAX = 64 * 1024; +// The id the host gives each owner message. A reply may name only such an id. +const OWNER_ID = /^owner-[0-9a-f]{12}$/; const CAP = /^[0-9a-f]{64}$/; // The spawn's environment: these names from the Console's own environment, PATH fixed, and the @@ -157,7 +159,8 @@ export function createRelay({ socket, cap, take, read, onSend, log = () => {} }) if (verb === "message.receive") return answer(conn, { ok: true, result: take() }); if (verb === "message.read") { read(args.id); return answer(conn, { ok: true, result: {} }); } if (verb === "message.send" && args.to === "human" && typeof args.body === "string" && args.body.length <= 32768) { - onSend({ body: args.body, in_reply_to: typeof args.in_reply_to === "string" ? args.in_reply_to : null }); + // Only an id the host issued is kept. The model writes this field, and the transcript serves it. + onSend({ body: args.body, in_reply_to: typeof args.in_reply_to === "string" && OWNER_ID.test(args.in_reply_to) ? args.in_reply_to : null }); return answer(conn, { ok: true, result: { id: `triage-${randomBytes(6).toString("hex")}` } }); } } catch (e) { diff --git a/packages/webui/tests/triage-cards.test.mjs b/packages/webui/tests/triage-cards.test.mjs index 5209c795f..20ac99786 100644 --- a/packages/webui/tests/triage-cards.test.mjs +++ b/packages/webui/tests/triage-cards.test.mjs @@ -74,6 +74,7 @@ test("no more than MAX_CARDS cards are kept", () => { test("the explanation is plain text: no control or direction characters, clipped", () => { assert.equal(plainText("a\u001b[31mred\u0007‮b\r\nc\td"), "a[31mredb\nc\td"); + assert.equal(plainText("a\u061cb\u180ec\u2028d\u2029e\ufefff"), "abcdef"); assert.equal(plainText("x".repeat(9000)).length, 8000); assert.equal(plainText(null), ""); assert.deepEqual(extractCards(null, orgs), { text: "", cards: [], dropped: 0 }); diff --git a/packages/webui/tests/triage-host.test.mjs b/packages/webui/tests/triage-host.test.mjs index fce0b9cca..e6d607b9c 100644 --- a/packages/webui/tests/triage-host.test.mjs +++ b/packages/webui/tests/triage-host.test.mjs @@ -52,7 +52,7 @@ test("the relay refuses every verb but a message to the person, and any call wit const dir = scratch(); const socket = join(dir, "relay.sock"); const sent = []; - const queue = [{ id: "owner-1", from_role: "human", class: "REQUEST", body: "hello", at: "2026-11-16T12:00:00.000Z" }]; + const queue = [{ id: "owner-0123456789ab", from_role: "human", class: "REQUEST", body: "hello", at: "2026-11-16T12:00:00.000Z" }]; const read = []; const server = await createRelay({ socket, cap: CAP, take: () => queue.splice(0), read: (id) => read.push(id), onSend: (m) => sent.push(m) }); t.after(() => server.close()); @@ -60,11 +60,17 @@ test("the relay refuses every verb but a message to the person, and any call wit assert.deepEqual(await client.call("role.claim"), { library: false }); assert.deepEqual(await client.call("processing.status"), { halted: false, invalid: false }); assert.deepEqual((await client.call("state")).tasks, { open: [], total: 0, cap: 0 }); - assert.deepEqual(await client.call("message.receive"), [{ id: "owner-1", from_role: "human", class: "REQUEST", body: "hello", at: "2026-11-16T12:00:00.000Z" }]); - assert.match((await client.call("message.send", { to: "human", body: "answer", class: "RESULT", in_reply_to: "owner-1" })).id, /^triage-/); - await client.call("message.read", { id: "owner-1" }); - assert.deepEqual(sent, [{ body: "answer", in_reply_to: "owner-1" }]); - assert.deepEqual(read, ["owner-1"]); + assert.deepEqual(await client.call("message.receive"), [{ id: "owner-0123456789ab", from_role: "human", class: "REQUEST", body: "hello", at: "2026-11-16T12:00:00.000Z" }]); + assert.match((await client.call("message.send", { to: "human", body: "answer", class: "RESULT", in_reply_to: "owner-0123456789ab" })).id, /^triage-/); + await client.call("message.read", { id: "owner-0123456789ab" }); + assert.deepEqual(sent, [{ body: "answer", in_reply_to: "owner-0123456789ab" }]); + assert.deepEqual(read, ["owner-0123456789ab"]); + // The model writes in_reply_to. Anything but an id the host issued is dropped, never stored. + for (const bad of ["", "owner-1", "owner-0123456789ab\u202e", "owner-0123456789abc", "x".repeat(60000)]) { + sent.length = 0; + await client.call("message.send", { to: "human", body: "b", in_reply_to: bad }); + assert.deepEqual(sent, [{ body: "b", in_reply_to: null }], bad.slice(0, 24)); + } const refused = [ ["decision.raise", { kind: "hire", body: "x" }], ["event.emit", { kind: "action.allowed", body: {} }], ["message.send", { to: "chief", body: "x", class: "INFO" }], ["message.send", { to: "pm", body: "x" }],