Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(pairing): strip invisible/bidi chars from phone names; cap by grapheme; guard doc scope

review096d287993ff
diff --git a/CLAUDE.md b/CLAUDE.md
index efb65380e..56cf5b72d 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -8322,7 +8322,7 @@ unix-socket forward over it. POSIX keeps OpenSSH untouched.
iOS app — which has never sent a name — is recognised by its fixed key comment `nodeterm-ios` and
keeps `'iPhone'`. Store links go through `renderer/lib/links.ts` `mobileStoreLinks()`; the Play
link is hidden by the single `ANDROID_APP_PUBLISHED` flag until the listing exists, and
- `mobileStore.guard.test.ts` refuses a direct store URL anywhere else. `LicenseSource` includes
+ `mobileStore.guard.test.ts` refuses a direct store URL anywhere else in the renderer. `LicenseSource` includes
`'google'` (a Play purchase bridged from the phone, `google:<orderId>`), with its own
`licenseCopy` sentence. `settings.mobileLiveActivities` keeps its key; the UI says "Live updates
on phone".
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 810aab6f6..52fdf7cb3 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -497,7 +497,7 @@ anything else. Board-level fields survive every transform — `pullLinks` is one
`nodeterm-mobile-<id>`, but revoke must keep matching the legacy `nodeterm-ios-<id>` stamp every
existing iPhone carries (`src/main/pairing-core.ts`). Link to a store only through
`mobileStoreLinks()` in `src/renderer/lib/links.ts` — the Play link stays hidden behind
- `ANDROID_APP_PUBLISHED` until the listing exists, and a guard test refuses direct store URLs.
+ `ANDROID_APP_PUBLISHED` until the listing exists, and a guard test refuses direct store URLs anywhere else in the renderer.
- **Relay pins are per role, and a revoke is one call.** Pin a peer only through its role's store
in `src/main/remote/approved-devices.ts` (`phonePins` is the only one anything auto-admits from —
diff --git a/src/main/pairing-core.test.ts b/src/main/pairing-core.test.ts
index bd35e51c6..c3c895f86 100644
--- a/src/main/pairing-core.test.ts
+++ b/src/main/pairing-core.test.ts
@@ -327,6 +327,23 @@ describe('normalizeDeviceName', () => {
expect(Array.from(out)).toHaveLength(64)
expect(out).toBe('📱'.repeat(64))
})
+
+ it('treats a name of only invisible / bidi characters as no name', () => {
+ expect(normalizeDeviceName('\u200B')).toBe('Phone')
+ // nodeterm-ios key
+ expect(normalizeDeviceName('\u202E\u200F', 'ssh-ed25519 AAAA nodeterm-ios')).toBe('iPhone')
+ expect(normalizeDeviceName('\u200D')).toBe('Phone')
+ })
+
+ it('strips zero-width and bidi characters from inside a name', () => {
+ expect(normalizeDeviceName('Pix\u200Bel\u202E 8')).toBe('Pixel 8')
+ })
+
+ it('caps by grapheme: a ZWJ emoji at the boundary is kept whole or cut whole, never dangling', () => {
+ const family = '\u{1F468}\u200D\u{1F469}\u200D\u{1F467}'
+ expect(normalizeDeviceName('a'.repeat(63) + family + 'b')).toBe('a'.repeat(63) + family)
+ expect(normalizeDeviceName('a'.repeat(64) + '\u{1F468}\u200D\u{1F469}')).toBe('a'.repeat(64))
+ })
})
describe('device registry helpers', () => {
diff --git a/src/main/pairing-core.ts b/src/main/pairing-core.ts
index 7402f360b..0ce2e1c24 100644
--- a/src/main/pairing-core.ts
+++ b/src/main/pairing-core.ts
@@ -3,6 +3,8 @@
// The QR payload + the authorized_keys line validation are the two bits of the pairing flow
// with a fixed on-the-wire contract shared with the nodeterm iOS app — keep them here, pure.
+import { CONTROL_RE } from '../core/relay/team-admin'
+
/**
* The relay block optionally embedded in the QR payload (and the /pair HTTP response). Present
* only when this host has phone-access (standing relay host) enabled + Pro, so the phone can
@@ -183,9 +185,14 @@ export type PublicDevice = Omit<DeviceEntry, 'token'>
/** The comment the shipped iOS app puts on the key it generates (nodeterm-ios PairingService). */
export const IOS_APP_KEY_COMMENT = 'nodeterm-ios'
-/** A phone-sent name is shown in Settings and sent as the relay label; keep it one short line. */
+/** A phone-sent name is shown in Settings and sent as the relay label; keep it one short line (graphemes). */
export const DEVICE_NAME_MAX = 64
+const CONTROL_RE_GLOBAL = new RegExp(CONTROL_RE.source, 'gu')
+/** Zero-width characters with no visible glyph (NOT U+200D, which joins emoji). */
+const INVISIBLE_RE = /[\u200B\u200C\u2060\uFEFF]/g
+const GRAPHEME_SEGMENTER = new Intl.Segmenter(undefined, { granularity: 'grapheme' })
+
/** The comment part of a public-key line (everything after type + blob), whitespace-collapsed. */
export function keyCommentOf(publicKey: string): string {
return normalizeAuthorizedKeysLine(publicKey).split(' ').slice(2).join(' ')
@@ -195,7 +202,11 @@ export function keyCommentOf(publicKey: string): string {
* The name a paired phone is listed (and relay-labelled) under.
*
* The name the phone sends wins — Android sends one. Control characters and newlines collapse to
- * single spaces and the result is capped at DEVICE_NAME_MAX code points (never splitting an emoji).
+ * single spaces; bidi / direction marks (the repo's Trojan-Source set, `CONTROL_RE`) become spaces
+ * too, and the zero-width characters U+200B, U+200C, U+2060 and U+FEFF are removed outright (U+200D
+ * is kept: it joins legitimate emoji). The result is capped at DEVICE_NAME_MAX GRAPHEMES, so a
+ * ZWJ emoji is kept whole or cut whole, never left with a dangling joiner. A name with no visible
+ * content after that (empty, or only U+200D) counts as no name.
* With no usable name the fallback is the neutral 'Phone' — EXCEPT for the iOS app, which has
* never sent a name: it is recognised by its fixed key comment and keeps the 'iPhone' every iPhone
* paired so far was given. Without that branch every newly paired iPhone would silently become
@@ -203,8 +214,16 @@ export function keyCommentOf(publicKey: string): string {
*/
export function normalizeDeviceName(name: unknown, publicKey = ''): string {
if (typeof name === 'string') {
- const flat = name.replace(/\p{Cc}/gu, ' ').replace(/\s+/g, ' ').trim()
- if (flat) return Array.from(flat).slice(0, DEVICE_NAME_MAX).join('').trim()
+ const flat = name
+ .replace(CONTROL_RE_GLOBAL, ' ')
+ .replace(INVISIBLE_RE, '')
+ .replace(/\s+/g, ' ')
+ .trim()
+ const capped = Array.from(GRAPHEME_SEGMENTER.segment(flat), (g) => g.segment)
+ .slice(0, DEVICE_NAME_MAX)
+ .join('')
+ .trim()
+ if (capped.replace(/\u200D/g, '').trim()) return capped
}
return keyCommentOf(publicKey) === IOS_APP_KEY_COMMENT ? 'iPhone' : 'Phone'
}