Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop): cap and normalize wire session titles on the read boundary

Diego Zacarias3c0d505503bc
diff --git a/desktop-app/src/rpcProxyClient.ts b/desktop-app/src/rpcProxyClient.ts
index 059cd7fff..aa0fecff5 100644
--- a/desktop-app/src/rpcProxyClient.ts
+++ b/desktop-app/src/rpcProxyClient.ts
@@ -67,9 +67,19 @@ function optionalWireString(value: unknown, label: string): string | undefined {
* `undefined` when nothing legible remains, so the caller falls back to the
* local cache or a placeholder instead of rendering a blank title.
*/
+// Mirror the server-side cap so a stale or hostile host cannot ship an oversized
+// title past the reader's trust boundary. The server rejects >120 code points with
+// a 400, so a legitimately stored title is always within this; on read we truncate
+// (a parser must not drop the whole session over a too-long title) rather than reject.
+const MAX_WIRE_TITLE_CODEPOINTS = 120
+
function sanitizeWireTitle(value: string): string | undefined {
const cleaned = value.replace(/[\p{C}\p{Zl}\p{Zp}]/gu, '').trim()
- return cleaned.length > 0 ? cleaned : undefined
+ if (cleaned.length === 0) return undefined
+ const points = Array.from(cleaned)
+ return points.length > MAX_WIRE_TITLE_CODEPOINTS
+ ? points.slice(0, MAX_WIRE_TITLE_CODEPOINTS).join('')
+ : cleaned
}
function wireSafeInteger(
@@ -1206,7 +1216,9 @@ export class RpcProxyClient {
const parsed = (await response.json().catch(() => ({}))) as { title?: unknown }
// Re-sanitize the server's echoed title on read (defense in depth, A14 rule).
const sanitized = typeof parsed.title === 'string' ? sanitizeWireTitle(parsed.title) : undefined
- return { title: sanitized ?? title }
+ // Fall back to the requested title if the server echo is missing/illegible,
+ // but sanitize that too so the same read-side normalization applies on every path.
+ return { title: sanitized ?? sanitizeWireTitle(title) ?? title }
}
async getDesktopStatus(
diff --git a/desktop-app/test/rpcProxyClient.test.ts b/desktop-app/test/rpcProxyClient.test.ts
index 0a3bfa387..5990c4e95 100644
--- a/desktop-app/test/rpcProxyClient.test.ts
+++ b/desktop-app/test/rpcProxyClient.test.ts
@@ -349,6 +349,17 @@ describe('parseSessionsListResult — title parse + sanitize on read (spec 15 §
expect(result.droppedItemCount).toBe(1)
})
+ it('truncates an oversized title from a stale/hostile host to the server cap (120 code points)', () => {
+ // The server rejects >120 code points with a 400, so a legit stored title is
+ // always within the cap; a host that returns more is not trusted. Emoji so a
+ // naive .length (UTF-16 units) would miscount vs the code-point cap.
+ const oversized = '😀'.repeat(200)
+ const result = parseSessionsListResult({ items: [{ ...baseItem, title: oversized }] })
+ const title = result.items[0]?.title as string
+ expect(Array.from(title)).toHaveLength(120)
+ expect(title).toBe('😀'.repeat(120))
+ })
+
it('strips line/paragraph separators (U+2028/U+2029) — single-line title', () => {
const result = parseSessionsListResult({
items: [{ ...baseItem, title: 'line1\u2028line2\u2029end' }],