{"record":{"id":"ff132bbe95977958","repo":"stablyai/orca","slug":"invalid-worktree-path","errorCode":null,"errorMessage":"Invalid worktree path","messagePattern":"Invalid worktree path","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main/ipc/worktree-logic.ts","lineNumber":84,"sourceCode":"    .replace(/[\\u202a-\\u202e\\u2066-\\u2069]/g, '')\n    .replace(/\\s+/g, ' ')\n    .trim()\n    .slice(0, 120)\n    .trim()\n\n  return sanitized || undefined\n}\n\n/**\n * Ensure a target path is within the workspace directory (prevent path traversal).\n */\nexport function ensurePathWithinWorkspace(targetPath: string, workspaceDir: string): string {\n  const resolvedWorkspaceDir = resolve(workspaceDir)\n  const resolvedTargetPath = resolve(targetPath)\n  const rel = relative(resolvedWorkspaceDir, resolvedTargetPath)\n\n  if (isAbsolute(rel) || rel === '..' || rel.startsWith(`..${sep}`)) {\n    throw new Error('Invalid worktree path')\n  }\n\n  return resolvedTargetPath\n}\n\n/**\n * Compute the filesystem path where the worktree directory will be created.\n *\n * Why WSL special case: when the repo lives on a WSL filesystem, worktrees\n * must also live on the WSL filesystem. Creating them on the Windows side\n * (/mnt/c/...) would be extremely slow due to cross-filesystem I/O and\n * the terminal would open a Windows shell instead of WSL. We mirror the\n * Windows workspace layout inside ~/orca/workspaces on the WSL filesystem\n * (e.g. \\\\wsl.localhost\\Ubuntu\\home\\user\\orca\\workspaces\\repo\\feature).\n */\nexport function computeWorktreePath(\n  sanitizedName: string,\n  repoPath: string,","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/ipc/worktree-logic.ts#L66-L102","documentation":"Thrown by ensurePathWithinWorkspace when the resolved targetPath escapes the workspaceDir. It computes the relative path from workspaceDir to targetPath and rejects if that relative path is absolute (different drive/root on Windows) or starts with '..'. This is the path-traversal guard preventing a worktree from being created outside the configured workspace directory, which could overwrite arbitrary files or break assumptions about containment.","triggerScenarios":"ensurePathWithinWorkspace(targetPath, workspaceDir) where targetPath resolves outside workspaceDir — e.g. '../sibling', an absolute path elsewhere, or a Windows path on a different drive than the workspace. The relative() result is absolute or begins with '..'.","commonSituations":"User-supplied or computed worktree path points outside the workspace root. Different drive letters on Windows (C: workspace vs D: target) make relative() return an absolute path. Symlink resolution moves the target outside. Misconfigured workspaceDir setting.","solutions":["Ensure targetPath is constructed as a child of workspaceDir (e.g. path.join(workspaceDir, name)).","Verify the workspaceDir setting points to the intended parent and is on the same drive/root.","If the user can specify a custom location, validate it resolves inside workspaceDir before calling ensure, and show a clear error."],"exampleFix":"// before\nensurePathWithinWorkspace('/etc/evil', '/home/user/orca/workspaces')\n// after\nensurePathWithinWorkspace('/home/user/orca/workspaces/repo/feature', '/home/user/orca/workspaces')","handlingStrategy":"validation","validationCode":"import { resolve, relative, isAbsolute, sep } from 'node:path'\nfunction isPathInsideWorkspace(targetPath: string, workspaceDir: string): boolean {\n  const rel = relative(resolve(workspaceDir), resolve(targetPath))\n  return !isAbsolute(rel) && rel !== '..' && !rel.startsWith(`..${sep}`)\n}","typeGuard":null,"tryCatchPattern":"try {\n  ensurePathWithinWorkspace(targetPath, workspaceDir)\n} catch (e) {\n  if (/Invalid worktree path/.test((e as Error).message)) {\n    showFieldError('path', 'Path must be inside the workspace directory.')\n    return\n  } else throw e\n}","preventionTips":["Construct target paths with path.join(workspaceDir, sub) rather than accepting raw input.","Keep workspaceDir and target on the same drive/root on Windows.","Validate containment with a relative-path check before calling ensure."],"tags":["worktree","path-traversal","security","validation","filesystem"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}