The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): resolve Windows shell paths before attachment previews
Ryan Hill8087af8550f9
diff --git a/apps/desktop/electron/local-read-path.windows.test.ts b/apps/desktop/electron/local-read-path.windows.test.tsnew file mode 100644index 00000000000..8ce38809874--- /dev/null+++ b/apps/desktop/electron/local-read-path.windows.test.ts@@ -0,0 +1,99 @@+import assert from 'node:assert/strict'+import fs from 'node:fs'+import os from 'node:os'+import path from 'node:path'+import { pathToFileURL } from 'node:url'++import { test } from 'vitest'++import { readFileDataUrlForIpc, resolveReadableFileForIpc, resolveRequestedPathForIpc } from './hardening'+import { resolveIpcFileReadPath, resolveMediaStreamFile, resolvePreviewTargetPath } from './local-read-path'+import { isWslBridgeActive, setWslBridgeActive } from './wsl-path-bridge'++test.runIf(process.platform === 'win32')(+ 'Windows shell attachments resolve and read through the native preview boundaries',+ async () => {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes-shell-preview-'))+ const bridgeWasActive = isWslBridgeActive()+ const source = path.join(dir, 'notes # 100% café.txt')+ const content = Buffer.from('LOCX-29: native preview reads the same attachment bytes.\n')++ const shellPath = (file: string, prefix = '') =>+ `/${prefix}${file[0].toLowerCase()}${file.slice(2).replace(/\\/g, '/')}`++ try {+ fs.writeFileSync(source, content)+ fs.writeFileSync(path.join(dir, '.env'), 'test-only')++ const targets = [+ source,+ pathToFileURL(source).href,+ ...['', 'cygdrive/', 'mnt/'].map(prefix => shellPath(source, prefix))+ ]++ // Native Windows backends can also have the WSL bridge enabled. Shell+ // drive paths must resolve before that bridge can reinterpret them as UNC.+ for (const bridgeActive of [false, true]) {+ setWslBridgeActive(bridgeActive)++ for (const target of targets) {+ const previewPath = resolveRequestedPathForIpc(+ resolvePreviewTargetPath(target, value => value),+ { baseDir: dir }+ )++ assert.equal(previewPath, source)+ assert.equal(fs.statSync(previewPath).isFile(), true)++ for (const readPath of [previewPath, resolveIpcFileReadPath(target), resolveMediaStreamFile(target)]) {+ const readable = await resolveReadableFileForIpc(readPath)+ assert.deepEqual(fs.readFileSync(readable.resolvedPath), content)+ assert.equal(+ await readFileDataUrlForIpc(readPath, { mimeType: 'text/plain' }),+ `data:text/plain;base64,${content.toString('base64')}`+ )+ }+ }+ }++ for (const prefix of ['', 'cygdrive/', 'mnt/']) {+ await assert.rejects(+ resolveReadableFileForIpc(resolveIpcFileReadPath(shellPath(path.join(dir, '.env'), prefix))),+ {+ code: 'sensitive-file'+ }+ )+ await assert.rejects(+ resolveReadableFileForIpc(resolveIpcFileReadPath(shellPath(path.join(dir, 'missing.txt'), prefix))),+ {+ code: 'ENOENT'+ }+ )+ await assert.rejects(+ resolveReadableFileForIpc(resolveIpcFileReadPath(shellPath(source, prefix)), { maxBytes: 1 }),+ { code: 'EFBIG' }+ )+ }++ assert.throws(() => resolveRequestedPathForIpc(resolveIpcFileReadPath('/c/Windows/GlobalRoot/Device/test')), {+ code: 'device-path'+ })+ assert.equal(resolveRequestedPathForIpc('\\\\server\\share\\notes.txt'), '\\\\server\\share\\notes.txt')+ } finally {+ setWslBridgeActive(bridgeWasActive)+ fs.rmSync(dir, { force: true, recursive: true })+ }+ }+)++test.runIf(process.platform !== 'win32')('POSIX shell-looking paths retain their native absolute meaning', () => {+ for (const target of ['/c/Users/notes.txt', '/cygdrive/c/notes.txt', '/mnt/c/notes.txt']) {+ for (const prepared of [+ resolvePreviewTargetPath(target, value => value),+ resolveIpcFileReadPath(target),+ resolveMediaStreamFile(target)+ ]) {+ assert.equal(resolveRequestedPathForIpc(prepared), target)+ }+ }+})diff --git a/apps/desktop/electron/wsl-path-bridge.test.ts b/apps/desktop/electron/wsl-path-bridge.test.tsindex 238e64a84ac..a028bb2aa88 100644--- a/apps/desktop/electron/wsl-path-bridge.test.ts+++ b/apps/desktop/electron/wsl-path-bridge.test.ts@@ -87,15 +87,17 @@ test('setWslBridgeActive(false) → resolvePickerDefaultPath passes raw path thrassert.equal(resolvePickerDefaultPath(undefined), undefined)})-test('setWslBridgeActive(false) → resolveLocalReadPath passes raw path through without bridging', () => {+test('setWslBridgeActive(false) → local reads normalize drive aliases without WSL bridging', () => {setWslBridgeActive(false)// resolveLocalReadPath is used by fs-read-dir to make WSL paths readable// on the Windows host. When the bridge is inactive (remote gateway), the- // raw POSIX path must be returned as-is — no UNC rewriting, no distro- // resolution. The downstream fs call will fail gracefully on non-WSL- // hosts, which is the desired behaviour.+ // non-drive POSIX path must be returned as-is — no UNC rewriting or+ // distro resolution. Windows drive aliases still identify native files.assert.equal(resolveLocalReadPath('/home/alex/proj'), '/home/alex/proj')- assert.equal(resolveLocalReadPath('/mnt/c/Users/alex'), '/mnt/c/Users/alex')+ assert.equal(+ resolveLocalReadPath('/mnt/c/Users/alex'),+ process.platform === 'win32' ? 'C:/Users/alex' : '/mnt/c/Users/alex'+ )// Non-POSIX paths are never bridged regardless of state.assert.equal(resolveLocalReadPath('C:\\Users\\alex'), 'C:\\Users\\alex')assert.equal(resolveLocalReadPath(''), '')diff --git a/apps/desktop/electron/wsl-path-bridge.ts b/apps/desktop/electron/wsl-path-bridge.tsindex c84d6bf6684..c818b4b9b9c 100644--- a/apps/desktop/electron/wsl-path-bridge.ts+++ b/apps/desktop/electron/wsl-path-bridge.ts@@ -184,6 +184,15 @@ export function resolvePickerDefaultPath(export function resolveLocalReadPath(dirPath: string, distro?: string, profile?: null | string): string {const value = String(dirPath || '').trim()+ // Native attachments can use Git Bash/Cygwin drive spelling even while the+ // local backend has WSL bridging enabled. Translate before the WSL fallback+ // turns /c/... into a nonexistent \\wsl.localhost\Ubuntu\c\... share.+ const shellDrive = IS_WINDOWS && value.match(/^\/(?:cygdrive\/|mnt\/)?([a-z])(?:\/|$)/i)++ if (shellDrive) {+ return `${shellDrive[1].toUpperCase()}:/${value.slice(shellDrive[0].length)}`+ }+// In remote-gateway mode the POSIX paths belong to a host the Windows// desktop cannot open locally — skip the WSL bridge entirely (no distro// probe, no wsl.exe) so the file panel never spawns the install prompt on