{"record":{"id":"664f3ee6a6f1db6e","repo":"thedotmack/claude-mem","slug":"rejected-path-traversal-attempt-in-watch-context-p","errorCode":null,"errorMessage":"Rejected path traversal attempt in watch.context.path","messagePattern":"Rejected path traversal attempt in watch\\.context\\.path","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/services/transcripts/processor.ts","lineNumber":376,"sourceCode":"    if (shouldSuppressNativeCodexAgentsContext(watch)) return;\n\n    const workerReady = await ensureWorkerRunning();\n    if (!workerReady) return;\n\n    const cwd = session.cwd ?? watch.workspace;\n    if (!cwd) return;\n\n    const context = getProjectContext(cwd);\n    const projectsParam = context.allProjects.join(',');\n\n    const contextUrl = `/api/context/inject?projects=${encodeURIComponent(projectsParam)}&platformSource=${encodeURIComponent(session.platformSource)}`;\n    const agentsPath = expandHomePath(watch.context.path ?? `${cwd}/AGENTS.md`);\n\n    const resolvedAgentsPath = path.resolve(agentsPath);\n    const allowedRoots = [path.resolve(cwd), path.resolve(DATA_DIR)];\n    const isPathSafe = allowedRoots.some(root => resolvedAgentsPath.startsWith(root + path.sep) || resolvedAgentsPath === root);\n    if (!isPathSafe) {\n      logger.warn('SECURITY', 'Rejected path traversal attempt in watch.context.path', {\n        original: watch.context.path,\n        resolved: resolvedAgentsPath,\n        allowedRoots\n      });\n      return;\n    }\n\n    let response: Awaited<ReturnType<typeof workerHttpRequest>>;\n    try {\n      response = await workerHttpRequest(contextUrl);\n    } catch (error: unknown) {\n      logger.warn('TRANSCRIPT', 'Failed to fetch AGENTS.md context', {\n        error: error instanceof Error ? error.message : String(error)\n      });\n      return;\n    }\n\n    if (!response.ok) return;","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/transcripts/processor.ts#L358-L394","documentation":"The transcript processor validates watch.context.path: after resolving it to an absolute path it must live under the project cwd or DATA_DIR. If the configured path escapes both roots it is treated as a path-traversal attempt and the update is silently refused (warning + return).","triggerScenarios":"updateContext (called from handleEvent/handleSessionEnd) receives a watch.context.path that resolves outside cwd and DATA_DIR, e.g. '../../etc/AGENTS.md', a symlink target outside the roots, or an absolute path in another project.","commonSituations":"A tool/session event carries a context path pointing at a file in another directory; misconfigured watch context referencing ~/ paths outside allowed roots; adversarial or buggy event payloads.","solutions":["Set watch.context.path to a path under the project cwd (e.g. <cwd>/AGENTS.md).","If the file legitimately lives elsewhere under claude-mem data, place/reference it under DATA_DIR.","Remove or fix the event source that injects out-of-root paths (check integrations writing watch.context).","If a root outside cwd/DATA_DIR is genuinely needed, it must be added to allowedRoots in processor.ts."],"exampleFix":"// before\nwatch.context.path = '/etc/AGENTS.md'\n// after\nwatch.context.path = '/home/user/project/AGENTS.md' // inside cwd","handlingStrategy":"validation","validationCode":"import path from 'path';\nfunction isWatchPathSafe(p, cwd, dataDir) {\n  const r = path.resolve(p);\n  return [cwd, dataDir].some(root => r === root || r.startsWith(root + path.sep));\n}","typeGuard":"function isUnderRoot(resolved: string, roots: string[]): boolean {\n  return roots.some(root => resolved.startsWith(root + path.sep) || resolved === root);\n}","tryCatchPattern":null,"preventionTips":["Never accept watch.context.path from untrusted event payloads without validating","Keep configured context paths inside the project directory","Beware symlinks: resolve before checking containment"],"tags":["security","path-traversal","validation"],"backgroundTag":"path-traversal-blocked","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}