thedotmack/claude-mem · warning

Rejected path traversal attempt in watch.context.path

Error message

Rejected path traversal attempt in watch.context.path

What it means

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).

Solutions

  1. Set watch.context.path to a path under the project cwd (e.g. <cwd>/AGENTS.md).
  2. If the file legitimately lives elsewhere under claude-mem data, place/reference it under DATA_DIR.
  3. Remove or fix the event source that injects out-of-root paths (check integrations writing watch.context).
  4. If a root outside cwd/DATA_DIR is genuinely needed, it must be added to allowedRoots in processor.ts.

Example fix

// before
watch.context.path = '/etc/AGENTS.md'
// after
watch.context.path = '/home/user/project/AGENTS.md' // inside cwd
Defensive patterns

Strategy: validation

Validate before calling

import path from 'path';
function isWatchPathSafe(p, cwd, dataDir) {
  const r = path.resolve(p);
  return [cwd, dataDir].some(root => r === root || r.startsWith(root + path.sep));
}

Type guard

function isUnderRoot(resolved: string, roots: string[]): boolean {
  return roots.some(root => resolved.startsWith(root + path.sep) || resolved === root);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.

Related errors


AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17). Data as JSON: /api/errors/664f3ee6a6f1db6e. Report an issue: GitHub.

Appendix: source

Thrown at src/services/transcripts/processor.ts:376

    if (shouldSuppressNativeCodexAgentsContext(watch)) return;

    const workerReady = await ensureWorkerRunning();
    if (!workerReady) return;

    const cwd = session.cwd ?? watch.workspace;
    if (!cwd) return;

    const context = getProjectContext(cwd);
    const projectsParam = context.allProjects.join(',');

    const contextUrl = `/api/context/inject?projects=${encodeURIComponent(projectsParam)}&platformSource=${encodeURIComponent(session.platformSource)}`;
    const agentsPath = expandHomePath(watch.context.path ?? `${cwd}/AGENTS.md`);

    const resolvedAgentsPath = path.resolve(agentsPath);
    const allowedRoots = [path.resolve(cwd), path.resolve(DATA_DIR)];
    const isPathSafe = allowedRoots.some(root => resolvedAgentsPath.startsWith(root + path.sep) || resolvedAgentsPath === root);
    if (!isPathSafe) {
      logger.warn('SECURITY', 'Rejected path traversal attempt in watch.context.path', {
        original: watch.context.path,
        resolved: resolvedAgentsPath,
        allowedRoots
      });
      return;
    }

    let response: Awaited<ReturnType<typeof workerHttpRequest>>;
    try {
      response = await workerHttpRequest(contextUrl);
    } catch (error: unknown) {
      logger.warn('TRANSCRIPT', 'Failed to fetch AGENTS.md context', {
        error: error instanceof Error ? error.message : String(error)
      });
      return;
    }

    if (!response.ok) return;

View on GitHub (pinned to d8bc9755e7)