Skip to content

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

TypeScript

fix(desktop): r3-m2 expand app tab title denylist, test final chrome

Diego Zacarias588af58b06f4
diff --git a/desktop-app/ui/src/components/WorkspaceTabStrip/WorkspaceTabStrip.test.tsx b/desktop-app/ui/src/components/WorkspaceTabStrip/WorkspaceTabStrip.test.tsx
index 761edc855..535ebece7 100644
--- a/desktop-app/ui/src/components/WorkspaceTabStrip/WorkspaceTabStrip.test.tsx
+++ b/desktop-app/ui/src/components/WorkspaceTabStrip/WorkspaceTabStrip.test.tsx
@@ -15,6 +15,7 @@ import {
openChatTab,
openSettingsTab,
reorderWorkspaceTab,
+ setAppTabTitle,
} from '@lib/workspaceTabs'
import type { WorkspaceTabsState } from '@lib/workspaceTabs.types'
import { WorkspaceTabStrip } from '.'
@@ -264,6 +265,39 @@ describe('WorkspaceTabStrip', () => {
})
})
+const cp = (code: number) => String.fromCodePoint(code)
+
+describe('WorkspaceTabStrip — sanitized plugin title reaches the rendered chrome', () => {
+ // The reviewer's ask: prove the FINAL workspace-tab label and the FINAL
+ // close-button accessible name are clean — not just the pure helper. The title
+ // travels the real border (`setAppTabTitle`) into the real store producer, so
+ // the render inherits whatever that path actually stores (T1: no hand-built
+ // tab). A pointer user sees the label; a screen-reader user hears the close
+ // button's accessible name; both must be free of the bidi/invisible payload.
+ it('strips bidi marks and invisibles from the tab label and close aria-label', () => {
+ // RLO + "EVIL" + PDF + " report" + LRM + ZWSP: a directional-override attack
+ // that would reverse the visible order plus a trailing invisible.
+ const raw = `${cp(0x202e)}EVIL${cp(0x202c)} report${cp(0x200e)}${cp(0x200b)}`
+ 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()}
+ />
+ )
+
+ expect(container.querySelector('.chat-view-tab__label')?.textContent).toBe('EVIL report')
+ expect(screen.getByRole('button', { name: 'Close EVIL report' })).toBeTruthy()
+ })
+})
+
describe('WorkspaceTabStrip — reorder (drag & keyboard)', () => {
// App tabs keep their ids and never dedupe, so this yields three distinct,
// stably-ordered tabs [a, b, c] derived from the real store producer (T1).
diff --git a/desktop-app/ui/src/lib/__tests__/sanitizeAppTabTitle.test.ts b/desktop-app/ui/src/lib/__tests__/sanitizeAppTabTitle.test.ts
index 3e74e11be..aff30a249 100644
--- a/desktop-app/ui/src/lib/__tests__/sanitizeAppTabTitle.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/sanitizeAppTabTitle.test.ts
@@ -5,18 +5,23 @@ import { sanitizeAppTabTitle } from '../sanitizeAppTabTitle'
const cp = (code: number) => String.fromCodePoint(code)
-// One representative code point per stripped range. Asserted against the real
-// sanitizer output (not a hand-copied regex), so a silent deletion of any range
-// from the source denylist fails this test.
+// 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.
const STRIPPED_REPRESENTATIVES: ReadonlyArray<readonly [string, number]> = [
['C0 low (U+0000–U+0008)', 0x0001],
['C0 high (U+000E–U+001F)', 0x000e],
['DEL (U+007F)', 0x007f],
['C1 (U+0080–U+009F)', 0x0085],
- ['zero-width (U+200B–U+200D)', 0x200c],
+ ['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],
['BOM / ZWNBSP (U+FEFF)', 0xfeff],
+ ['invisible tag char (U+E0001)', 0xe0001],
]
const hasLoneSurrogate = (s: string) =>
@@ -46,6 +51,18 @@ describe('sanitizeAppTabTitle (mini-spec 08 §2)', () => {
expect(sanitizeAppTabTitle('a\tb\nc')).toBe('a b c')
})
+ 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.
+ 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)
+ })
+
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)
diff --git a/desktop-app/ui/src/lib/sanitizeAppTabTitle.ts b/desktop-app/ui/src/lib/sanitizeAppTabTitle.ts
index 0438b81f5..f5c719769 100644
--- a/desktop-app/ui/src/lib/sanitizeAppTabTitle.ts
+++ b/desktop-app/ui/src/lib/sanitizeAppTabTitle.ts
@@ -10,36 +10,52 @@ 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 non-whitespace C0/C1 control characters (whitespace controls such as
- * tab/newline survive removal so they can be collapsed, not dropped);
- * - remove bidi overrides/embeddings/isolates and zero-width / BOM code points;
+ * - 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;
* - 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.
+ *
* 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.
+ * 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.
*
- * Ranges: non-whitespace C0 (U+0000-U+0008, U+000E-U+001F), DEL + C1
- * (U+007F-U+009F), zero-width (U+200B-U+200D), bidi overrides/embeddings
- * (U+202A-U+202E), bidi isolates (U+2066-U+2069), and BOM/ZWNBSP (U+FEFF).
- * U+0009-U+000D (tab, LF, VT, FF, CR) are intentionally NOT removed here: they
- * are whitespace and collapse to a single space in the next step.
+ * 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.
*/
const UNSAFE_RANGES: ReadonlyArray<readonly [number, number]> = [
- [0x0000, 0x0008],
- [0x000e, 0x001f],
- [0x007f, 0x009f],
- [0x200b, 0x200d],
- [0x202a, 0x202e],
- [0x2066, 0x2069],
- [0xfeff, 0xfeff],
+ [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, 0x200d], // ZWSP, ZWNJ, ZWJ (zero-width)
+ [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(