{"record":{"id":"926b91b7bb0155f3","repo":"JuliusBrussee/caveman","slug":"pending-label-transaction-has-unsafe-permission","errorCode":null,"errorMessage":"pending ${label} transaction has unsafe permissions; refusing recovery","messagePattern":"pending (.+?) transaction has unsafe permissions; refusing recovery","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":12736,"sourceCode":"function readOwnedMcpPendingJournalAt(\n  path: string,\n  expected: { agent?: \"kilo\" | \"qwen\"; serverName?: string; configPath?: string; locatorPath?: string } = {},\n): ReadOwnedMcpPendingJournal | null {\n  const label = ownedMcpPendingLabel(expected.agent, expected.serverName);\n  let bytes: Buffer;\n  let value: Record<string, unknown>;\n  try {\n    bytes = readFileSync(path);\n    value = JSON.parse(bytes.toString(\"utf8\")) as Record<string, unknown>;\n  } catch (error) {\n    if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return null;\n    throw new Error(`cannot read pending ${label} transaction: ${(error as Error).message}`);\n  }\n  if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n    throw new Error(`pending ${label} transaction is malformed; refusing recovery`);\n  }\n  if (process.platform !== \"win32\" && (statSync(path).mode & 0o077) !== 0) {\n    throw new Error(`pending ${label} transaction has unsafe permissions; refusing recovery`);\n  }\n  const keys = [\n    \"action\", \"agent\", \"config_after_sha256\", \"config_before_base64\", \"config_before_mode\", \"config_path\",\n    \"config_before_sha256\", \"marker_after_base64\", \"marker_after_sha256\", \"marker_before_base64\", \"marker_before_mode\",\n    \"marker_before_sha256\", \"marker_path\", \"schema_version\", \"server_name\", \"transaction_id\",\n  ].sort();\n  const journalAgent = value.agent;\n  const journalServer = value.server_name;\n  if (Object.keys(value).sort().join(\"\\0\") !== keys.join(\"\\0\")\n    || value.schema_version !== 1\n    || typeof value.transaction_id !== \"string\"\n    || !/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(value.transaction_id)\n    || (journalAgent !== \"kilo\" && journalAgent !== \"qwen\")\n    || typeof journalServer !== \"string\"\n    || !mcpServerToolName(journalServer)\n    || (expected.agent !== undefined && journalAgent !== expected.agent)\n    || (expected.serverName !== undefined && journalServer !== expected.serverName)\n    || (value.action !== \"install\" && value.action !== \"uninstall\")","sourceCodeStart":12718,"sourceCodeEnd":12754,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L12718-L12754","documentation":"Pending transaction journals must be private: on POSIX systems the file mode is checked and any group/other permission bits (mode & 0o077 != 0) cause recovery to refuse, because the journal embeds config contents and could leak data. Windows is exempt from this check.","triggerScenarios":"The journal file was created or chmod'ed with group/other read/write bits set (e.g. mode 644 or 664 instead of 600), typically by a tool using a non-restrictive umask or a manual chmod.","commonSituations":"Copying the journal from another machine or archive that carried wider permissions; running with a permissive umask (e.g. umask 000) that affected file creation; a shared workspace resetting permissions.","solutions":["chmod 600 <journal-file> to strip group/other permission bits and re-run recovery","Set a restrictive umask (umask 077) before running the CLI so new journals are created private","Check parent directory permissions if the tool keeps recreating files with wide modes"],"exampleFix":"// before\nls -l pending.json  # -rw-r--r-- (644)\n// after\nchmod 600 pending.json  # -rw------- (600)","handlingStrategy":"validation","validationCode":"import { statSync } from 'fs';\nfunction journalPermissionsSafe(path: string): boolean {\n  if (process.platform === 'win32') return true;\n  return (statSync(path).mode & 0o077) === 0;\n}\n// fix proactively: chmod 600 path","typeGuard":"function hasSafeJournalMode(path: string): boolean {\n  try { return process.platform === 'win32' || (statSync(path).mode & 0o077) === 0; }\n  catch { return false; }\n}","tryCatchPattern":"try {\n  recoverPendingTransaction(label, path);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('unsafe permissions')) {\n    chmodSync(path, 0o600);\n    return recoverPendingTransaction(label, path); // retry once\n  }\n  throw e;\n}","preventionTips":["Set umask 077 in shells/CI that run the CLI","Never chmod journal files to group/other-readable","Preserve original permissions when copying journals between machines","Audit shared directories whose ACLs may widen effective permissions"],"tags":["permissions","security","journal","mcp"],"backgroundTag":"insufficient-permissions","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"}