{"record":{"id":"53356c1ac8f701b7","repo":"JuliusBrussee/caveman","slug":"path-is-a-symlink-refusing-transactional-owner","errorCode":null,"errorMessage":"${path} is a symlink; refusing transactional ownership mutation","messagePattern":"(.+?) is a symlink; refusing transactional ownership mutation","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":10633,"sourceCode":"// bare name so callers' existing missing-binary handling still triggers.\nfunction cavemanBin(name: string, envVar: string): string {\n  const explicit = process.env[envVar];\n  if (explicit) return explicit;\n  const onPath = which(name);\n  if (onPath) return onPath;\n  const local = join(cavemanHome(), \"bin\", binaryInstallFilename(name));\n  if (isExecutable(local)) return local;\n  return name;\n}\nfunction mcpServerMarkerPath(agentId: string, serverName: string): string {\n  return join(cavemanHome(), \"mcp\", serverName === \"caveman\" ? `${agentId}.json` : `${agentId}.${serverName}.json`);\n}\n\nfunction canonicalOwnedMcpMarkerPath(agent: \"kilo\" | \"qwen\", serverName: string): string {\n  const path = mcpServerMarkerPath(agent, serverName);\n  try {\n    if (lstatSync(path).isSymbolicLink()) {\n      throw new Error(`${path} is a symlink; refusing transactional ownership mutation`);\n    }\n  } catch (error) {\n    if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n  }\n  return canonicalMcpConfigPath(path);\n}\n\n// A native MCP registration and its Caveman ownership journal form one logical\n// write. Prove the journal directory is writable before touching agent config;\n// otherwise Kilo/Qwen would refuse both a later upgrade and removal because the\n// surviving registration has no trustworthy owner.\nfunction preflightMcpServerMarker(agentId: string, serverName: string): void {\n  const path = mcpServerMarkerPath(agentId, serverName);\n  const probe = join(dirname(path), `.${basename(path)}.preflight-${process.pid}-${randomUUID()}`);\n  try {\n    mkdirSync(dirname(path), { recursive: true, mode: 0o700 });\n    chmodSync(dirname(path), 0o700);\n    durableAtomicWriteFile(probe, Buffer.alloc(0));","sourceCodeStart":10615,"sourceCodeEnd":10651,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L10615-L10651","documentation":"Before mutating MCP ownership markers transactionally for the kilo/qwen agents, the CLI resolves the canonical marker path and refuses to proceed if the marker path itself is a symbolic link. Mutating through a symlink could write outside the intended location, so it is treated as a safety violation. ENOENT (marker not yet created) is tolerated.","triggerScenarios":"Calling an ownership transaction (install/uninstall MCP ownership journal) where `lstatSync(markerPath)` reports the existing marker is a symlink — typically because a user replaced the marker file with a link, or a dotfile manager symlinked config/marker directories.","commonSituations":"Dotfile management (stow, chezmoi, nix home-manager) symlinking ~/.config subtrees where the CLI writes markers; restoring markers from a backup tool that converted files to links; moving a marker to another disk with a symlink.","solutions":["Remove the symlink at the reported path and replace it with a real file (copy the target's content, then `unlink` the link and write the file)","Exclude the CLI's marker paths from your dotfile symlink management so they are real files","Re-run the install/uninstall command after the path is a regular file"],"exampleFix":"# before\n$ ls -l ~/.kilo/markers/caveman\ncaveman -> /mnt/backup/caveman-marker\n# after\n$ cp --remove-destination \"$(readlink ~/.kilo/markers/caveman)\" ~/.kilo/markers/caveman","handlingStrategy":"validation","validationCode":"import { lstatSync } from \"node:fs\";\nconst marker = mcpServerMarkerPath(agent, serverName);\ntry { if (lstatSync(marker).isSymbolicLink()) throw new Error(\"marker is a symlink; fix before transaction\"); } catch (e) { if ((e as any).code !== \"ENOENT\") throw e; }","typeGuard":"function isRegularFile(p: string): boolean {\n  try { return lstatSync(p).isFile(); } catch { return false; }\n}","tryCatchPattern":"try {\n  await runOwnershipTransaction(agent, serverName);\n} catch (e) {\n  if ((e as Error).message.includes(\"is a symlink\")) {\n    console.error(\"Replace the symlinked marker with a real file, then retry.\");\n  } else throw e;\n}","preventionTips":["Exclude CLI marker/config paths from stow/chezmoi/nix symlink management","Audit marker paths for symlinks before scripted installs","Restore markers as real files, not links, from backups","Never replace CLI-written files with symlinks"],"tags":["security","symlink","filesystem"],"backgroundTag":"path-traversal-blocked","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}