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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(explorer): treat a backslash as a separator in the new-entry traversal guard
albaneselorenzofb7a3696ae4d
diff --git a/src/renderer/lib/explorerCreate.test.ts b/src/renderer/lib/explorerCreate.test.tsindex 44d0d085c..1131c9f67 100644--- a/src/renderer/lib/explorerCreate.test.ts+++ b/src/renderer/lib/explorerCreate.test.ts@@ -28,6 +28,31 @@ describe('newEntryPath', () => {expect(newEntryPath('/repo', 'a/../../evil')).toBeNull()expect(newEntryPath('/repo', 'a/')).toBeNull()})++ // The hole eneskirca spotted on #294: `..` was only ever looked for between `/` separators, so+ // a backslash-delimited traversal was one segment that is neither empty nor `..`. It passed on+ // every platform and escaped `baseDir` as soon as Windows resolved it.+ it('rejects a backslash traversal, which used to pass as a single segment', () => {+ expect(newEntryPath('/repo', '..\\evil')).toBeNull()+ expect(newEntryPath('/repo', 'a\\..\\..\\evil')).toBeNull()+ expect(newEntryPath('/repo', 'a/..\\evil')).toBeNull()+ expect(newEntryPath('/repo', 'a\\../evil')).toBeNull()+ })++ it('rejects a name that is absolute in the Windows dialect', () => {+ expect(newEntryPath('/repo', '\\Windows\\system32')).toBeNull()+ expect(newEntryPath('/repo', 'C:\\Windows')).toBeNull()+ expect(newEntryPath('/repo', 'C:/Windows')).toBeNull()+ expect(newEntryPath('/repo', 'a\\')).toBeNull()+ })++ // CONTRIBUTING is explicit that the two separators are NOT interchangeable: on POSIX a+ // backslash is ordinary filename text. The guard reads both dialects, the construction stays+ // `/`, and a legal POSIX name survives.+ it('still accepts a backslash as ordinary filename text', () => {+ expect(newEntryPath('/repo', 'weird\\name.txt')).toBe('/repo/weird\\name.txt')+ expect(newEntryPath('/repo', 'a\\\\b')).toBe('/repo/a\\\\b')+ })})describe('ancestorDirs', () => {diff --git a/src/renderer/lib/explorerCreate.ts b/src/renderer/lib/explorerCreate.tsindex 014ebe90c..93a1dfa8f 100644--- a/src/renderer/lib/explorerCreate.ts+++ b/src/renderer/lib/explorerCreate.ts@@ -14,13 +14,28 @@ export function parentDir(p: string): string {/*** Join a user-entered name onto a base dir. Multi-segment relative names (`a/b.ts`) are- * allowed — intermediate dirs are the caller's job (see `ancestorDirs`). Returns null for- * anything unsafe or senseless: empty, absolute, `..` traversal, trailing slash.+ * allowed, and the intermediate dirs are the caller's job (see `ancestorDirs`). Returns null for+ * anything unsafe or senseless: empty, absolute, `..` traversal, trailing separator.+ *+ * The `..` guard splits on BOTH separators, the rule CONTRIBUTING states for every path split:+ * `..\x` used to be a single segment that was neither empty nor `..`, so it passed here on every+ * platform and then escaped `baseDir` the moment Windows resolved it. That is the same hole the+ * node-icon traversal check had, and the same fix.+ *+ * The path is still BUILT with `/`, and the empty-segment check still splits on `/` alone, on+ * purpose: on POSIX a backslash is ordinary filename text, so `a\\b` is a legal name for one file+ * and refusing it would be this guard being wrong about the filesystem it is writing to. Guard on+ * both dialects, construct in one.*/export function newEntryPath(baseDir: string, name: string): string | null {const n = name.trim()- if (!n || n.startsWith('/') || n.endsWith('/')) return null- if (n.split('/').some((seg) => !seg || seg === '..')) return null+ if (!n) return null+ // Absolute in either dialect escapes `baseDir`, which is the whole point of joining onto it:+ // a leading `/`, a leading `\` (root of the current Windows drive), or a drive qualifier.+ if (n.startsWith('/') || n.startsWith('\\') || /^[A-Za-z]:/.test(n)) return null+ if (n.endsWith('/') || n.endsWith('\\')) return null+ if (n.split(/[\\/]/).some((seg) => seg === '..')) return null+ if (n.split('/').some((seg) => !seg)) return nullreturn `${baseDir.replace(/\/+$/, '')}/${n}`}