Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): sanitize GFS names rendered in the file explorer tree chrome
Diego Zacarias0f7179c4d1fd
diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsxindex 0cb68ae1d..284bc8f92 100644--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx@@ -154,6 +154,40 @@ describe('FileExplorerTree — sort ordering', () => {})})+describe('FileExplorerTree — sanitizes externally-controlled GFS names in chrome', () => {+ it('cleans bidi/zero-width code points from the folder label and its toggle accessible name', async () => {+ installClerum({+ listAccessible: vi.fn(async () => ({+ // A GFS folder name carrying a bidi override + zero-width — attacker input.+ items: [node('evil', `Reports`, 'directory')],+ nextCursor: null,+ })),+ })++ renderTree()++ // The visible label and the toggle's accessible name both show the sanitized+ // string; the raw bidi/zero-width variant never reaches the accessible tree.+ expect(await screen.findByRole('button', { name: 'Reports' })).toBeTruthy()+ expect(screen.getByRole('button', { name: 'Expand Reports' })).toBeTruthy()+ expect(screen.queryByRole('button', { name: `Reports` })).toBeNull()+ })++ it('shows the cleaned name in the download toast while the raw name stays for the on-disk file', async () => {+ installClerum({+ listAccessible: vi.fn(async () => ({+ items: [node('z', `archive.zip`, 'file')],+ nextCursor: null,+ })),+ })++ const { pushToast } = renderTree()++ fireEvent.doubleClick(await screen.findByRole('button', { name: 'archive.zip' }))+ await waitFor(() => expect(pushToast).toHaveBeenCalledWith('Downloaded archive.zip', 'success'))+ })+})+describe('FileExplorerTree — single-vs-double click cancels the deferred single', () => {// The real browser fires click → click → dblclick; a single fireEvent.doubleClick// dispatches only dblclick, so it never exercises the setTimeout cancellation.diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsxindex 5e16fb00a..630d7dc7e 100644--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx@@ -10,6 +10,7 @@ import {} from '@hooks/domain/useGfsBrowserController'import { saveGfsFileToDisk } from '@lib/gfsDownload'import { resolveGfsPreview } from '@lib/gfsPreview'+import { sanitizeAppTabTitle } from '@lib/sanitizeAppTabTitle'import { IconChevronRight, IconContexts } from '../icons'import type { FileExplorerNodeProps, FileExplorerTreeProps } from './types'@@ -23,6 +24,17 @@ function errorMessage(error: unknown): string | null {return error instanceof Error ? error.message : String(error)}+// A GFS name is externally controlled (anyone who can write to a shared drive the+// viewer sees), so it must not reach the sidebar chrome raw: bidi overrides can+// disguise an extension, zero-width code points spoof a trusted file, control+// chars corrupt the tree. Clean it with the same sanitizer the workspace-tab+// titles use, before it lands in a visible label, an accessible name, or a toast.+// The raw name is still used for the real on-disk download and for the icon's+// extension parsing — neither is a display surface.+function displayName(name: string): string {+ return sanitizeAppTabTitle(name) || 'Unnamed'+}+/** Folders first, then files, each alphabetical — the VSCode tree ordering. */function sortTreeItems(items: GfsBrowserChild[]): GfsBrowserChild[] {return [...items].sort((left, right) => {@@ -54,6 +66,7 @@ function FileExplorerNode({const isDirectory = node.kind === 'directory'const isExpanded = isDirectory && expandedIds.has(node.resourceId)const isSelected = selectedId === node.resourceId+ const label = displayName(node.name)const childQuery = useInfiniteQuery({queryKey: desktopQueryKeys.gfsChildren(scope, node.resourceId, GFS_DRIVE_MAIN),@@ -137,7 +150,7 @@ function FileExplorerNode({<IconButtonaria-expanded={isExpanded}className={`da-file-explorer__toggle${isExpanded ? ' is-expanded' : ''}`}- label={`${isExpanded ? 'Collapse' : 'Expand'} ${node.name}`}+ label={`${isExpanded ? 'Collapse' : 'Expand'} ${label}`}onClick={() => onToggle(node.resourceId)}size="sm"variant="ghost"@@ -160,7 +173,7 @@ function FileExplorerNode({<span className="da-file-explorer__icon" aria-hidden="true">{isDirectory ? <IconContexts /> : <GfsFileIcon name={node.name} />}</span>- <span className="da-file-explorer__name">{node.name}</span>+ <span className="da-file-explorer__name">{label}</span></Button></div>{isExpanded ? (@@ -266,8 +279,9 @@ export function FileExplorerTree({}void (async () => {try {+ // The raw name is the real on-disk filename; the toast shows the cleaned one.await saveGfsFileToDisk(node.gfsUri, node.name)- pushToast(`Downloaded ${node.name}`, 'success')+ pushToast(`Downloaded ${displayName(node.name)}`, 'success')} catch (error) {const message = error instanceof Error ? error.message : String(error)if (authorityFailure(message, 'operation')) return