{"record":{"id":"a5be4d3915713a12","repo":"nexu-io/open-design","slug":"project-files-read-json-does-not-follow-symlinks","errorCode":null,"errorMessage":"project_files.read_json does not follow symlinks","messagePattern":"project_files\\.read_json does not follow symlinks","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/daemon/src/live-artifacts/refresh.ts","lineNumber":592,"sourceCode":"      size: file.size,\n      mtime: file.mtime,\n      kind: file.kind ?? 'file',\n      mime: file.mime ?? 'application/octet-stream',\n    };\n    if (preview !== undefined) result.preview = preview;\n    matches.push(result);\n  }\n\n  return asBoundedRefreshOutput({ toolName: 'project_files.search', query: query ?? '', count: matches.length, truncated: allFiles.length > matches.length && matches.length >= maxResults, matches });\n}\n\nasync function executeProjectFilesReadJson(options: ExecuteLocalDaemonRefreshSourceOptions): Promise<BoundedJsonObject> {\n  const filePath = selectJsonPath(options.source.input as ProjectFilesReadJsonInput);\n  if (!filePath.endsWith('.json')) throw new Error('project_files.read_json only supports .json files');\n  const dir = projectDir(options.projectsRoot, options.projectId);\n  const target = path.resolve(dir, filePath);\n  const [dirReal, targetLinkStat] = await Promise.all([realpath(dir), lstat(target)]);\n  if (targetLinkStat.isSymbolicLink()) throw new Error('project_files.read_json does not follow symlinks');\n  const targetReal = await realpath(target);\n  if (!targetReal.startsWith(`${dirReal}${path.sep}`) && targetReal !== dirReal) {\n    throw new Error('project_files.read_json path escapes project dir');\n  }\n  const entryStat = await stat(targetReal);\n  if (!entryStat.isFile()) throw new Error('project_files.read_json path must be a file');\n  if (entryStat.size > 256 * 1024) throw new Error('project_files.read_json file exceeds 256KB');\n  if (options.signal?.aborted === true) throw options.signal.reason;\n  let parsed: BoundedJsonValue;\n  try {\n    parsed = JSON.parse(await readFile(targetReal, 'utf8')) as BoundedJsonValue;\n  } catch {\n    throw new Error(`project_files.read_json could not parse JSON at ${filePath}`);\n  }\n  return asBoundedRefreshOutput({ toolName: 'project_files.read_json', path: filePath, size: entryStat.size, json: parsed });\n}\n\nfunction compactExecOutput(value: string): string[] {","sourceCodeStart":574,"sourceCodeEnd":610,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/live-artifacts/refresh.ts#L574-L610","documentation":"executeProjectFilesReadJson (refresh.ts:590-591) calls lstat on the resolved target and refuses to proceed if it is a symbolic link. This prevents a symlink from redirecting the read outside the validated project directory after the realpath boundary check would be bypassed.","triggerScenarios":"input.path resolves (via path.resolve) to a filesystem entry whose lstat reports it as a symbolic link, even if the link target is inside the project.","commonSituations":"A project contains symlinks (e.g. node_modules-style linking, monorepo workspace links, a symlinked config file); a user symlinked a shared data file into the project.","solutions":["Read the real file directly instead of through a symlink (place a real copy under the project dir).","Remove or replace the symlink with the actual JSON file.","If the link is intentional and trusted, expose its target as a normal file in the project."],"exampleFix":"// before: project has  data.json -> /shared/data.json (symlink)\nconst input = { path: 'data.json' };\n// throws `project_files.read_json does not follow symlinks`\n\n// after: replace the symlink with a real file\n// cp /shared/data.json ./data.json  (regular file)","handlingStrategy":"validation","validationCode":"import { lstat } from 'node:fs/promises';\nasync function assertNotSymlink(target: string): Promise<void> {\n  const st = await lstat(target);\n  if (st.isSymbolicLink()) {\n    throw new Error('project_files.read_json does not follow symlinks');\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep real (non-symlinked) JSON files in the project for read_json sources.","When staging project files, copy rather than symlink data files.","Audit project trees for symlinks before pointing read_json at them."],"tags":["live-artifacts","project-files","symlink","security"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}