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(project-icons): native emoji (CSP), lazy sharp, tab icon box, sanitize no-op guard, avatar fetch timeout

enesf993a0ff7626
diff --git a/src/core/github/avatar-fetcher.ts b/src/core/github/avatar-fetcher.ts
index e8b4c2b73..315abd3d0 100644
--- a/src/core/github/avatar-fetcher.ts
+++ b/src/core/github/avatar-fetcher.ts
@@ -46,7 +46,8 @@ export async function fetchAvatarDataUrl(
parsed.username || parsed.password) return null
let response: Response
try {
- response = await fetchImpl(parsed, { method: 'GET', redirect: 'manual' })
+ // 10s cap so a hung avatar host can't leave the fetch pending; abort → rejected fetch → null.
+ response = await fetchImpl(parsed, { method: 'GET', redirect: 'manual', signal: AbortSignal.timeout(10_000) })
} catch {
return null
}
diff --git a/src/core/github/project-avatar.test.ts b/src/core/github/project-avatar.test.ts
index 1462bead5..c8f497257 100644
--- a/src/core/github/project-avatar.test.ts
+++ b/src/core/github/project-avatar.test.ts
@@ -116,6 +116,18 @@ describe('resolveProjectAvatarDataUrl', () => {
expect(dataUrl).toBeNull()
})
+ it('bounds the users request with an abort signal (hung connection can never hang forever)', async () => {
+ let seenSignal: unknown
+ await resolveProjectAvatarDataUrl({
+ owner: 'acme',
+ fetchImpl: async (_url, init) => {
+ seenSignal = init?.signal
+ return userJson(AVATAR)
+ }
+ })
+ expect(seenSignal).toBeInstanceOf(AbortSignal)
+ })
+
it('rejects an owner that would escape the users path', async () => {
let called = false
const dataUrl = await resolveProjectAvatarDataUrl({
diff --git a/src/core/github/project-avatar.ts b/src/core/github/project-avatar.ts
index 404542ab3..6b188acf9 100644
--- a/src/core/github/project-avatar.ts
+++ b/src/core/github/project-avatar.ts
@@ -52,6 +52,9 @@ export async function resolveProjectAvatarDataUrl(deps: {
const response = await fetchImpl(url, {
method: 'GET',
redirect: 'manual',
+ // A hung connection must not leave the probe pending for the section's lifetime: abort after
+ // 10s. The abort surfaces as a rejected fetch → caught below → null (the never-throw envelope).
+ signal: AbortSignal.timeout(10_000),
headers: {
accept: 'application/vnd.github+json',
'x-github-api-version': API_VERSION,
diff --git a/src/main/project-icon-upload.ts b/src/main/project-icon-upload.ts
index d5dd5030a..0ee1c2f15 100644
--- a/src/main/project-icon-upload.ts
+++ b/src/main/project-icon-upload.ts
@@ -1,5 +1,4 @@
import { promises as fsp } from 'node:fs'
-import sharp from 'sharp'
import {
dataUrlByteLength,
PROJECT_ICON_MAX_BYTES,
@@ -18,6 +17,15 @@ import {
* so main `require`s it from node_modules) and is listed in electron-builder `asarUnpack`, so its
* platform binary sits unpacked beside the app. Both are required for this to work in a packaged
* build — without them the require would fail and the upload would be dead.
+ *
+ * The import is LAZY (`await import('sharp')` inside the encode function, mirroring
+ * speech-service.ts's smart-whisper load) rather than a top-level `import sharp from 'sharp'`. A
+ * top-level import loads libvips at every boot — and this module is reached at main's module scope
+ * (index.ts imports `pickProjectIcon`), so a bad packaged `@img/*` layout / wrong-arch binary would
+ * throw during `require('sharp')` and kill the WHOLE main process at startup, not just this feature.
+ * Loading it inside the encode path — and mapping a load/encode failure to the existing `{ error }`
+ * result — degrades a broken sharp to "the upload button doesn't work" instead of "the app won't
+ * start".
*/
/** The longest edge (px) a re-encoded icon is bounded to. Square box, `fit: 'inside'` preserves
@@ -36,6 +44,9 @@ export async function encodeProjectIconImage(
): Promise<{ dataUrl: string } | { error: string }> {
let png: Buffer
try {
+ // Lazy load: a missing/wrong-arch native binary throws HERE (caught below → { error }) rather
+ // than at main's boot, so a broken sharp layout degrades to a dead upload, not a dead app.
+ const sharp = (await import('sharp')).default
png = await sharp(input)
.resize(ICON_MAX_DIMENSION, ICON_MAX_DIMENSION, { fit: 'inside', withoutEnlargement: true })
.png()
diff --git a/src/renderer/components/TabBar.tsx b/src/renderer/components/TabBar.tsx
index 40c1453e2..0a0625e6c 100644
--- a/src/renderer/components/TabBar.tsx
+++ b/src/renderer/components/TabBar.tsx
@@ -307,7 +307,9 @@ export function TabBar({
color={active ? p.color : undefined}
name={p.name}
variant="dot"
- className="tab__dot"
+ // With an icon set, the glyph needs a larger, tint-free box (--icon modifier);
+ // without one it stays the plain 9px fallback dot, byte-identical to before.
+ className={p.icon ? 'tab__dot tab__dot--icon' : 'tab__dot'}
/>
{/* An SSH project looks identical to a local one once it is named, and the
difference matters: its terminals, git and file ops all run on another
diff --git a/src/renderer/components/settings/EmojiPickerLazy.tsx b/src/renderer/components/settings/EmojiPickerLazy.tsx
index e235b62d5..29eeaaa94 100644
--- a/src/renderer/components/settings/EmojiPickerLazy.tsx
+++ b/src/renderer/components/settings/EmojiPickerLazy.tsx
@@ -15,6 +15,9 @@ const EmojiPicker = lazy(() => import('emoji-picker-react')) as React.LazyExotic
React.ComponentType<{
autoFocusSearch?: boolean
theme?: 'dark' | 'light' | 'auto'
+ // The library's `EmojiStyle` enum resolves to these plain strings at runtime; typed loosely
+ // here (like `theme`) to avoid importing the enum at module scope. 'native' renders OS glyphs.
+ emojiStyle?: 'native' | 'apple' | 'twitter' | 'google' | 'facebook'
lazyLoadEmojis?: boolean
onEmojiClick?: (data: { emoji: string }) => void
width?: string | number
@@ -34,6 +37,11 @@ export default function EmojiPickerLazy({ dark, onEmoji }: EmojiPickerLazyProps)
<EmojiPicker
autoFocusSearch={false}
theme={dark ? 'dark' : 'light'}
+ // Render OS-native emoji glyphs. The library defaults to EmojiStyle.APPLE, which emits every
+ // emoji as an <img src="https://cdn.jsdelivr.net/…"> — blocked outright by the renderer CSP
+ // (img-src 'self' data: nt-media:), so the whole grid would be broken images + blocked CDN
+ // requests. 'native' (EmojiStyle.NATIVE) uses the font, offline-clean and CSP-safe.
+ emojiStyle="native"
lazyLoadEmojis
width="100%"
height={340}
diff --git a/src/renderer/components/settings/ProjectIconPicker.test.tsx b/src/renderer/components/settings/ProjectIconPicker.test.tsx
index 3b58b05e2..a3bc89cee 100644
--- a/src/renderer/components/settings/ProjectIconPicker.test.tsx
+++ b/src/renderer/components/settings/ProjectIconPicker.test.tsx
@@ -10,15 +10,26 @@ import { ProjectIconPicker } from './ProjectIconPicker'
// The heavy library is mocked with a factory that counts how many times it is EVALUATED. Because
// EmojiPickerLazy imports it dynamically (React.lazy), the factory does not run until the Emoji tab
// is actually rendered — which is exactly the laziness this pins.
-const H = vi.hoisted(() => ({ emojiLoads: 0 }))
+const H = vi.hoisted(() => ({ emojiLoads: 0, lastEmojiStyle: undefined as string | undefined }))
vi.mock('emoji-picker-react', () => {
H.emojiLoads++
return {
- default: ({ onEmojiClick }: { onEmojiClick?: (d: { emoji: string }) => void }) => (
- <button data-testid="fake-emoji" onClick={() => onEmojiClick?.({ emoji: '🚀' })}>
- pick
- </button>
- )
+ default: ({
+ onEmojiClick,
+ emojiStyle
+ }: {
+ onEmojiClick?: (d: { emoji: string }) => void
+ emojiStyle?: string
+ }) => {
+ // Record the style the wrapper passes: it MUST be 'native', or the picker renders emoji as
+ // <img src="https://cdn.jsdelivr.net/…"> which the renderer CSP blocks (broken grid).
+ H.lastEmojiStyle = emojiStyle
+ return (
+ <button data-testid="fake-emoji" onClick={() => onEmojiClick?.({ emoji: '🚀' })}>
+ pick
+ </button>
+ )
+ }
}
})
@@ -67,6 +78,7 @@ describe('ProjectIconPicker', () => {
beforeEach(() => {
H.emojiLoads = 0
+ H.lastEmojiStyle = undefined
host = document.createElement('div')
document.body.appendChild(host)
onIcon = vi.fn()
@@ -104,6 +116,24 @@ describe('ProjectIconPicker', () => {
expect(onIcon).toHaveBeenCalledWith({ type: 'emoji', emoji: '🚀' })
})
+ it('renders the emoji picker with the native style (CSP-safe, no CDN images)', async () => {
+ await mount()
+ await click(tab('Emoji'))
+ await flush()
+ expect(H.lastEmojiStyle).toBe('native')
+ })
+
+ it('does NOT clear the icon when a picked value fails sanitize (no-op, not a destructive emit)', async () => {
+ // An upload whose dataUrl is not a real data: URL sanitizes to undefined. The guard must BAIL
+ // (Reset is the only clear), not emit undefined — which would clear+persist the icon.
+ pickProjectIcon.mockResolvedValue({ dataUrl: 'not-a-data-url' })
+ await mount({ type: 'emoji', emoji: '🚀' })
+ await click(tab('Upload'))
+ await click([...host.querySelectorAll('button')].find((b) => b.textContent === 'Choose image…')!)
+ await flush()
+ expect(onIcon).not.toHaveBeenCalled()
+ })
+
it('re-encodes an uploaded image into an image icon via the main IPC', async () => {
await mount()
await click(tab('Upload'))
diff --git a/src/renderer/components/settings/ProjectIconPicker.tsx b/src/renderer/components/settings/ProjectIconPicker.tsx
index a60d6e75c..60e75d0c4 100644
--- a/src/renderer/components/settings/ProjectIconPicker.tsx
+++ b/src/renderer/components/settings/ProjectIconPicker.tsx
@@ -59,7 +59,14 @@ export function ProjectIconPicker({
const [avatarAvailable, setAvatarAvailable] = useState(false)
const [avatarError, setAvatarError] = useState<string | undefined>(undefined)
- const commit = (raw: ProjectIcon): void => onIcon(sanitizeProjectIcon(raw))
+ // A choice is sanitized before it leaves — and if sanitize REJECTS it (undefined), we BAIL rather
+ // than emit undefined: an emit would clear+persist the icon, the opposite of a picker action.
+ // Reset stays the only explicit clear. (A sanitized picker value is always defined today, so this
+ // is a guard against a latent destructive edge, not a reachable path.)
+ const commit = (raw: ProjectIcon): void => {
+ const sanitized = sanitizeProjectIcon(raw)
+ if (sanitized) onIcon(sanitized)
+ }
// Latest icon/onIcon read from the open-time probe without making them effect deps (which would
// re-fire the probe on every icon edit).
@@ -93,7 +100,10 @@ export function ProjectIconPicker({
setAvatarAvailable(true)
const cur = iconRef.current
if (cur?.type === 'image' && cur.source === 'github' && cur.src !== res.dataUrl) {
- onIconRef.current(sanitizeProjectIcon({ type: 'image', src: res.dataUrl, source: 'github' }))
+ // Same no-op guard as `commit`: only re-commit if the fresh src survives sanitize; a reject
+ // must NOT blank the already-set github icon (that would be the opposite of anti-clobber).
+ const sanitized = sanitizeProjectIcon({ type: 'image', src: res.dataUrl, source: 'github' })
+ if (sanitized) onIconRef.current(sanitized)
}
})()
return () => {
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index e83a5fa30..d4b3af353 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -312,6 +312,18 @@ body,
background: rgba(var(--tint-rgb), 0.3);
}
+/* When the project has a real icon (emoji / lucide / image) the glyph replaces the plain 9px
+ fallback dot: a larger box (an emoji is ~13px and would overflow 9px, and a lucide/image glyph
+ would be clipped) with NO baked-in tint background (that tint circle only belongs to the fallback
+ dot). Applied by TabBar only when `p.icon` is set; the plain `.tab__dot` fallback is untouched.
+ 16px matches the other project-glyph surfaces; the exact px wants a live Mac look, so it's tunable. */
+.tab__dot--icon {
+ width: 16px;
+ height: 16px;
+ border-radius: 0;
+ background: none;
+}
+
/* Unread-completion count badge on a project tab. */
.tab__badge {
display: inline-flex;