Skip to content

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

TypeScript

fix(desktop): r6-b1 sanitize app tab titles by unicode default-ignorable policy

Diego Zacarias108c0f7d1864
diff --git a/desktop-app/ui/src/components/WorkspaceTabStrip/WorkspaceTabStrip.test.tsx b/desktop-app/ui/src/components/WorkspaceTabStrip/WorkspaceTabStrip.test.tsx
index 0cef9f58a..96b282df9 100644
--- a/desktop-app/ui/src/components/WorkspaceTabStrip/WorkspaceTabStrip.test.tsx
+++ b/desktop-app/ui/src/components/WorkspaceTabStrip/WorkspaceTabStrip.test.tsx
@@ -5,6 +5,7 @@ import { ChatListProvider } from '@contexts/ChatListContext'
import { cleanup, createEvent, fireEvent, render, screen } from '@testing-library/react'
import { readFileSync } from 'node:fs'
import path from 'node:path'
+import { MAX_TAB_TITLE_LEN } from '@constants/workspaceTabs'
import { createSessionFsmStore, projectSessionState } from '@hooks/domain/sessionFsm'
import {
closeWorkspaceTab,
@@ -319,6 +320,38 @@ describe('WorkspaceTabStrip — sanitized plugin title reaches the rendered chro
expect(container.querySelector('.chat-view-tab__label')?.textContent).toBe(withEmoji)
expect(screen.getByRole('button', { name: `Close ${withEmoji}` })).toBeTruthy()
})
+
+ it('bounds an overlong untrusted title in both the rendered label and the close aria-label', () => {
+ // The reviewer's overlong case: a very long title with a leading bidi
+ // override and trailing invisibles. The final label AND the close-button
+ // accessible name must be the truncated, stripped value — not the raw
+ // payload, not a value that overflows the tab into the close control.
+ const raw = `${cp(0x202e)}${'A'.repeat(100)}${cp(0x200b)}${cp(0xfeff)}`
+ // Derived independently of the sanitizer: the invisibles vanish, leaving 100
+ // 'A's truncated to MAX-1 plus the ellipsis.
+ const expected = `${'A'.repeat(MAX_TAB_TITLE_LEN - 1)}…`
+ const state = setAppTabTitle(
+ openAppTab(createEmptyWorkspaceTabsState(), { id: 'app-1', appRef: 'ns/app', title: 'App' }),
+ 'app-1',
+ raw
+ )
+ const { container } = render(
+ <WorkspaceTabStrip
+ tabs={state.tabs}
+ activeTabId="app-1"
+ onSelect={vi.fn()}
+ onClose={vi.fn()}
+ onReorder={vi.fn()}
+ />
+ )
+
+ const label = container.querySelector('.chat-view-tab__label')?.textContent ?? ''
+ expect(label).toBe(expected)
+ expect(Array.from(label).length).toBe(MAX_TAB_TITLE_LEN)
+ expect(label.endsWith('…')).toBe(true)
+ expect(label.includes(cp(0x202e))).toBe(false)
+ expect(screen.getByRole('button', { name: `Close ${expected}` })).toBeTruthy()
+ })
})
describe('WorkspaceTabStrip — reorder (drag & keyboard)', () => {
diff --git a/desktop-app/ui/src/lib/__tests__/sanitizeAppTabTitle.test.ts b/desktop-app/ui/src/lib/__tests__/sanitizeAppTabTitle.test.ts
index db47fe8f6..d2a77973f 100644
--- a/desktop-app/ui/src/lib/__tests__/sanitizeAppTabTitle.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/sanitizeAppTabTitle.test.ts
@@ -5,23 +5,32 @@ import { sanitizeAppTabTitle } from '../sanitizeAppTabTitle'
const cp = (code: number) => String.fromCodePoint(code)
-// One representative code point per denylisted range. Asserted against the real
-// sanitizer output (not a hand-copied regex), so a silent narrowing of the
-// removal policy in the source fails this test.
+// A representative invisible code point per class the policy removes: control
+// chars (\p{Cc} minus whitespace), the Default_Ignorable_Code_Point set, and
+// the interlinear-annotation anchors. Asserted against the real sanitizer
+// output (not a hand-copied regex), so a silent narrowing of the removal policy
+// in the source fails this test. The last three (soft hyphen, Mongolian vowel
+// separator, Hangul filler) are the invisibles later review rounds kept finding
+// one at a time; the property-based policy now removes them by definition.
const STRIPPED_REPRESENTATIVES: ReadonlyArray<readonly [string, number]> = [
- ['C0 low (U+0000–U+0008)', 0x0001],
- ['C0 high (U+000E–U+001F)', 0x000e],
+ ['C0 low (U+0001)', 0x0001],
+ ['C0 high (U+000E)', 0x000e],
['DEL (U+007F)', 0x007f],
- ['C1 (U+0080–U+009F)', 0x0085],
+ ['C1 NEL (U+0085)', 0x0085],
['zero-width space (U+200B)', 0x200b],
['LRM bidi mark (U+200E)', 0x200e],
['RLM bidi mark (U+200F)', 0x200f],
['ALM bidi mark (U+061C)', 0x061c],
['word joiner (U+2060)', 0x2060],
- ['bidi override (U+202A–U+202E)', 0x202e],
- ['bidi isolate (U+2066–U+2069)', 0x2066],
+ ['bidi override RLO (U+202E)', 0x202e],
+ ['bidi isolate LRI (U+2066)', 0x2066],
['BOM / ZWNBSP (U+FEFF)', 0xfeff],
+ ['interlinear annotation anchor (U+FFF9)', 0xfff9],
['invisible tag char (U+E0001)', 0xe0001],
+ ['musical formatter (U+1D173, astral)', 0x1d173],
+ ['soft hyphen (U+00AD)', 0x00ad],
+ ['Mongolian vowel separator (U+180E)', 0x180e],
+ ['Hangul filler (U+3164)', 0x3164],
]
const hasLoneSurrogate = (s: string) =>
@@ -52,26 +61,40 @@ describe('sanitizeAppTabTitle (mini-spec 08 §2)', () => {
})
it('preserves legitimate non-Latin script format characters (collateral of R3-M2)', () => {
- // The Cf category also holds script-shaping formatters that are real text,
- // not hazards. A category-based strip (\p{Cf}) corrupts them; the explicit
- // denylist must leave every one intact. Repro of the collateral regression:
- // 'سورة۝٢' carries U+06DD (ARABIC END OF AYAH), a visible verse ornament.
+ // The Cf category holds script-shaping formatters that are real, VISIBLE
+ // text, not hazards. A category-based strip (\p{Cf}) corrupts them; Unicode
+ // excludes them from Default_Ignorable_Code_Point, so the policy leaves them
+ // intact. Repro of the collateral regression: 'سورة۝٢' carries U+06DD
+ // (ARABIC END OF AYAH), a visible verse ornament.
const arabicAyah = `سورة${cp(0x06dd)}${cp(0x0662)}`
expect(sanitizeAppTabTitle(arabicAyah)).toBe(arabicAyah)
expect(sanitizeAppTabTitle(`a${cp(0x0600)}b`)).toBe(`a${cp(0x0600)}b`) // ARABIC NUMBER SIGN
expect(sanitizeAppTabTitle(`a${cp(0x070f)}b`)).toBe(`a${cp(0x070f)}b`) // SYRIAC ABBREV MARK
- expect(sanitizeAppTabTitle(`a${cp(0x1d173)}b`)).toBe(`a${cp(0x1d173)}b`) // musical (astral)
+ expect(sanitizeAppTabTitle(`a${cp(0x13430)}b`)).toBe(`a${cp(0x13430)}b`) // Egyptian control (astral)
})
it('preserves the ZWJ/ZWNJ shaping joiners (legitimate Unicode, not a hazard)', () => {
// ZWJ (U+200D) fuses an emoji sequence into one glyph; stripping it splits
// 👩‍💻 into 👩💻. ZWNJ (U+200C) controls shaping/ligatures in Persian and
- // Indic scripts. The denylist leaves the U+200C-U+200D gap open for both.
+ // Indic scripts. The Join_Control carve-out keeps both.
const zwjEmoji = `Build ${cp(0x1f469)}${cp(0x200d)}${cp(0x1f4bb)}`
expect(sanitizeAppTabTitle(zwjEmoji)).toBe(zwjEmoji)
expect(sanitizeAppTabTitle(`a${cp(0x200c)}b`)).toBe(`a${cp(0x200c)}b`)
})
+ it('preserves variation selectors so emoji presentation and CJK variants survive', () => {
+ // Variation selectors are invisible (Default_Ignorable) BUT shape the
+ // adjacent glyph: VS16 (U+FE0F) makes ❤ render as the coloured emoji ❤️,
+ // keycaps (1️⃣ = '1' + VS16 + U+20E3) depend on it, and the ideographic
+ // selectors pick CJK glyph variants. The Variation_Selector carve-out keeps
+ // them; a blanket Default_Ignorable strip would silently corrupt the title.
+ const heart = `${cp(0x2764)}${cp(0xfe0f)}` // ❤️
+ expect(sanitizeAppTabTitle(heart)).toBe(heart)
+ const keycap = `1${cp(0xfe0f)}${cp(0x20e3)}` // 1️⃣
+ expect(sanitizeAppTabTitle(keycap)).toBe(keycap)
+ expect(sanitizeAppTabTitle(`a${cp(0xe0100)}b`)).toBe(`a${cp(0xe0100)}b`) // ideographic VS17
+ })
+
it('truncates to MAX_TAB_TITLE_LEN with a trailing ellipsis', () => {
const out = sanitizeAppTabTitle('x'.repeat(MAX_TAB_TITLE_LEN + 50))
expect(out.length).toBe(MAX_TAB_TITLE_LEN)
@@ -103,14 +126,18 @@ describe('sanitizeAppTabTitle (mini-spec 08 §2)', () => {
0x007f,
0x0085,
0x009f,
+ 0x00ad, // soft hyphen (stripped)
+ 0x180e, // Mongolian vowel separator (stripped)
0x2028,
0x2029,
0x200b,
- 0x200d,
+ 0x200c, // ZWNJ (kept — shaping)
+ 0x200d, // ZWJ (kept — shaping)
0x202a,
0x202e,
0x2066,
0x2069,
+ 0xfe0f, // VS16 (kept — shaping)
0xfeff,
0x09,
0x0a,
diff --git a/desktop-app/ui/src/lib/sanitizeAppTabTitle.ts b/desktop-app/ui/src/lib/sanitizeAppTabTitle.ts
index 8dafeb3b5..088e223de 100644
--- a/desktop-app/ui/src/lib/sanitizeAppTabTitle.ts
+++ b/desktop-app/ui/src/lib/sanitizeAppTabTitle.ts
@@ -10,70 +10,63 @@ import { MAX_TAB_TITLE_LEN } from '../constants/workspaceTabs'
* the cleaned value from the store, so none re-sanitizes.
*
* The contract (pure, idempotent: `sanitize(sanitize(x)) === sanitize(x)`):
- * - remove the code points in `UNSAFE_RANGES` — non-whitespace C0/C1 controls,
- * DEL, the bidi marks/overrides/embeddings/isolates, zero-width and other
- * invisible formatters, BOM, interlinear-annotation anchors, and the astral
- * Unicode tag characters;
+ * - remove every code point that Unicode itself defines as non-rendering — the
+ * control category `\p{Cc}` (minus whitespace, handled below) and the
+ * `Default_Ignorable_Code_Point` set (bidi marks/overrides/embeddings/
+ * isolates, zero-width formatters, word joiner, BOM, Hangul fillers, the
+ * astral tag characters, and the rest of the standard's "ignore in rendering"
+ * set) — plus the interlinear-annotation anchors U+FFF9–U+FFFB;
* - collapse any run of whitespace to a single space and trim;
* - truncate to `MAX_TAB_TITLE_LEN` code points, replacing the tail with an
* ellipsis so the result never exceeds the bound;
* - an input that is empty after sanitizing yields `''`: the caller keeps the
* previous title rather than blanking the tab.
*
- * WHY an explicit numeric-range denylist and NOT the Unicode categories
- * `\p{Cc}\p{Cf}`: the format category `\p{Cf}` also contains legitimate,
- * script-shaping code points that real titles use and must survive — e.g. the
- * Arabic sign/number marks (U+0600-U+0605, U+06DD ARABIC END OF AYAH, a VISIBLE
- * ornament around a verse number), the Syriac abbreviation mark (U+070F), Kaithi
- * (U+110BD/U+110CD), Egyptian-hieroglyph format controls (U+13430-U+13440), and
- * musical-notation formatters (U+1D173-U+1D17A). Stripping the whole Cf category
- * corrupts non-Latin text; the denylist targets only the actual layout/order/
- * invisibility hazards and leaves every legitimate script formatter alone.
+ * WHY the `Default_Ignorable_Code_Point` PROPERTY and not an enumerated list of
+ * ranges: an enumerated denylist of invisible characters is never finished —
+ * there is always one more zero-width code point to add, and each addition is a
+ * new review round. `Default_Ignorable_Code_Point` is Unicode's own, versioned
+ * definition of exactly "code points that should be ignored in rendering" — the
+ * invisible set. It ALREADY excludes the legitimate, VISIBLE script formatters
+ * that a real title uses (e.g. U+0600–U+0605 and U+06DD ARABIC END OF AYAH,
+ * U+070F SYRIAC ABBREVIATION MARK, U+110BD/U+110CD Kaithi, U+13430–U+13440
+ * Egyptian-hieroglyph controls), so they survive with no per-code-point
+ * carve-out. The runtime resolves the property from its own Unicode version
+ * (Chromium in the renderer, Node under test); the ignorable ranges are stable
+ * by design, including the unassigned tail of the tag / plane-14 blocks.
*
- * The two zero-width SHAPING joiners are likewise preserved: ZWNJ (U+200C) and
- * ZWJ (U+200D). ZWJ fuses an emoji sequence into one glyph (stripping it splits
- * a "woman technologist" into a separate woman + laptop); ZWNJ controls
- * ligatures/shaping in Persian and Indic scripts. The denylist leaves the gap
- * U+200C-U+200D open between the ZWSP entry (U+200B) and the bidi marks (U+200E-
- * U+200F) for exactly this reason.
+ * TWO invisible-but-SHAPING exceptions are kept, because they change the
+ * rendering of the ADJACENT glyph rather than being pure decoration:
+ * - `\p{Join_Control}` — ZWJ (U+200D) fuses an emoji sequence into one glyph
+ * (stripping it splits a "woman technologist" 👩‍💻 into a separate 👩 + 💻);
+ * ZWNJ (U+200C) controls ligatures/shaping in Persian and Indic scripts.
+ * - `\p{Variation_Selector}` — VS16 (U+FE0F) is what makes ❤️ render as a
+ * coloured emoji rather than the text glyph ❤, keycaps (1️⃣) depend on it, and
+ * the ideographic selectors (U+E0100–U+E01EF) pick CJK glyph variants in real
+ * names. Stripping these silently corrupts a legitimate, visible title.
*
- * The denylist is declared as numeric code-point ranges and compiled with
- * `new RegExp`, NOT written as embedded literal bytes or `\u` escapes. A
- * security denylist built from invisible characters can be mutated with no
- * visible diff by an editor or formatter pass; numeric ranges keep every
- * stripped span legible and diff-safe in review, and the compiled regex still
- * matches the exact code points. The `u` flag lets a range whose bounds are
- * built with `String.fromCodePoint` (e.g. the astral tag chars U+E0000-U+E007F)
- * match those code points singly rather than as surrogate halves.
+ * Whitespace controls U+0009–U+000D are excluded from the `\p{Cc}` removal via
+ * the `(?!\s)` guard: they must survive so the next step collapses them to a
+ * single space instead of gluing adjacent words together. (U+0085 NEL is
+ * `\p{Cc}` but not `\s`, so it is stripped, not kept.)
*
- * U+0009-U+000D (tab, LF, VT, FF, CR) are intentionally absent from the denylist:
- * they are whitespace, survive the removal, and collapse to a single space in the
- * next step rather than gluing adjacent words together.
+ * U+FFF9–U+FFFB (interlinear annotation anchors) are the one range Unicode does
+ * NOT count as Default_Ignorable, so they are named explicitly — as `\u` escapes,
+ * never the literal invisible bytes, so an editor or formatter pass cannot mutate
+ * this security denylist with no visible diff.
+ *
+ * NOT covered — deliberately: a title built only from visible-but-blank glyphs
+ * (e.g. U+2800 BRAILLE PATTERN BLANK) renders as an empty-looking tab. No
+ * invisible-character filter can catch that (the glyph is visible, just empty),
+ * and it is not a spoofing vector here — the label is free text shown to its
+ * own owner, never compared against a trusted string. It is a UX edge, not a
+ * sanitizer gap.
*/
-const UNSAFE_RANGES: ReadonlyArray<readonly [number, number]> = [
- [0x0000, 0x0008], // C0 controls (excludes tab/LF/VT/FF/CR)
- [0x000e, 0x001f], // C0 controls (excludes CR)
- [0x007f, 0x009f], // DEL + C1 controls
- [0x061c, 0x061c], // ARABIC LETTER MARK (bidi)
- [0x200b, 0x200b], // ZWSP (U+200C ZWNJ / U+200D ZWJ deliberately preserved)
- [0x200e, 0x200f], // LRM, RLM (bidi marks)
- [0x202a, 0x202e], // LRE, RLE, PDF, LRO, RLO (bidi embeddings/overrides)
- [0x2060, 0x2064], // WORD JOINER + invisible math operators
- [0x2066, 0x2069], // LRI, RLI, FSI, PDI (bidi isolates)
- [0xfeff, 0xfeff], // BOM / ZWNBSP
- [0xfff9, 0xfffb], // interlinear annotation anchors
- [0xe0000, 0xe007f], // Unicode tag characters (astral; invisible fingerprinting)
-]
-
-const STRIP_UNSAFE_CHARS = new RegExp(
- `[${UNSAFE_RANGES.map(([lo, hi]) =>
- lo === hi ? String.fromCodePoint(lo) : `${String.fromCodePoint(lo)}-${String.fromCodePoint(hi)}`
- ).join('')}]`,
- 'gu'
-)
+const STRIP_INVISIBLE =
+ /(?!\s)\p{Cc}|(?![\p{Join_Control}\p{Variation_Selector}])\p{Default_Ignorable_Code_Point}|[\uFFF9-\uFFFB]/gu
export function sanitizeAppTabTitle(raw: string): string {
- const collapsed = raw.replace(STRIP_UNSAFE_CHARS, '').replace(/\s+/g, ' ').trim()
+ const collapsed = raw.replace(STRIP_INVISIBLE, '').replace(/\s+/g, ' ').trim()
// Count and slice by code point, not UTF-16 code unit, so truncation never
// splits a surrogate pair and leaves a lone half dangling before the ellipsis.
const points = Array.from(collapsed)