{"record":{"id":"36f8cb706b088def","repo":"Yeachan-Heo/oh-my-codex","slug":"refusing-cancellation-through-non-regular-state-ta","errorCode":null,"errorMessage":"Refusing cancellation through non-regular state target ${ref.path}.","messagePattern":"Refusing cancellation through non-regular state target (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/cli/index.ts","lineNumber":8407,"sourceCode":"        string,\n        {\n          path: string;\n          scope: \"root\" | \"session\";\n          state: Record<string, unknown>;\n          originalContent: string;\n          dev: number;\n          ino: number;\n        }\n      >();\n      if (refs.length === 0) return loaded;\n      const canonicalAuthorityRoot = assertCancellationAuthorityPath(\n        authorityRoot === writableScope.stateDir ? baseStateDir : authorityRoot,\n        authorityRoot,\n      );\n      for (const ref of refs) {\n        const fileStat = lstatSync(ref.path);\n        if (!fileStat.isFile() || fileStat.isSymbolicLink()) {\n          throw new Error(`Refusing cancellation through non-regular state target ${ref.path}.`);\n        }\n        const canonicalPath = realpathSync(ref.path);\n        const canonicalParent = realpathSync(dirname(ref.path));\n        if (!isCanonicalPathWithin(canonicalAuthorityRoot, canonicalParent, true)\n          || !isCanonicalPathWithin(canonicalAuthorityRoot, canonicalPath)) {\n          throw new Error(`Refusing cancellation outside authorized state root: ${ref.path}.`);\n        }\n        const content = await readFile(canonicalPath, \"utf-8\");\n        let parsedState: Record<string, unknown>;\n        try {\n          const parsed = JSON.parse(content) as unknown;\n          if (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n            throw new Error(\"state must be a JSON object\");\n          }\n          parsedState = parsed as Record<string, unknown>;\n        } catch (err) {\n          logCliOperationFailure(err);\n          throw new Error(`Refusing partial cancellation because ${ref.path} is malformed.`, { cause: err });","sourceCodeStart":8389,"sourceCodeEnd":8425,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/cli/index.ts#L8389-L8425","documentation":"Before touching state files, the cancel command lstats each referenced path and requires it to be a regular file that is not a symbolic link. If the target is a symlink, directory, fifo, or missing/special file, cancellation refuses to proceed. This blocks attacks and accidents where state paths are redirected via links.","triggerScenarios":"A state file reference resolving to a symlink (e.g. state.json -> /etc/something), a directory, or a deleted/non-regular path. lstatSync is used deliberately so symlinks themselves are detected rather than followed.","commonSituations":"Users symlinking state directories between machines or into dotfiles repos; backup tools replacing files with links; state dir moved and linked back; containerized setups sharing state via links.","solutions":["Replace the symlink at the referenced path with a real regular file (copy contents, remove link)","Point configuration at the actual state directory instead of linking into it","Restore the state file if it was replaced by a link during a move","Avoid symlinked state paths; use bind mounts or direct paths instead"],"exampleFix":"# before\nln -s /shared/state.json ~/.omx/state.json\n# after\ncp /shared/state.json ~/.omx/state.json","handlingStrategy":"type-guard","validationCode":"import { lstatSync } from \"node:fs\";\nfunction isRegularStateFile(path: string): boolean {\n  try {\n    const st = lstatSync(path);\n    return st.isFile() && !st.isSymbolicLink();\n  } catch {\n    return false;\n  }\n}","typeGuard":"import { Stats } from \"node:fs\";\nfunction isRegularFile(stat: Stats): boolean {\n  return stat.isFile() && !stat.isSymbolicLink();\n}","tryCatchPattern":null,"preventionTips":["Never symlink individual state files","Audit state directories for links after restores or moves","Exclude state dirs from backup tools that recreate files as links"],"tags":["security","filesystem","symlink","cancel","state"],"backgroundTag":"symlink-traversal-refused","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}