{"record":{"id":"3ae00e5613417d47","repo":"mastra-ai/mastra","slug":"invalid-mount-path-mountpath-path-segments-ca","errorCode":null,"errorMessage":"Invalid mount path: ${mountPath}. Path segments cannot be \".\" or \"..\".","messagePattern":"Invalid mount path: (.+?)\\. Path segments cannot be \"\\.\" or \"\\.\\.\"\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/workspace/sandbox/local-sandbox.ts","lineNumber":72,"sourceCode":"export function getMarkerDir(): string {\n  return path.join(os.tmpdir(), '.mastra-mounts');\n}\n\n/** Allowlist pattern for mount paths — absolute path with safe characters only. */\nconst SAFE_MOUNT_PATH = /^\\/[a-zA-Z0-9_.\\-/]+$/;\n\nfunction validateMountPath(mountPath: string): void {\n  if (!SAFE_MOUNT_PATH.test(mountPath)) {\n    throw new Error(\n      `Invalid mount path: ${mountPath}. Must be an absolute path with alphanumeric, dash, dot, underscore, or slash characters only.`,\n    );\n  }\n  const segments = mountPath.split('/').filter(Boolean);\n  if (segments.length === 0) {\n    throw new Error(`Invalid mount path: ${mountPath}. Root path \"/\" is not allowed.`);\n  }\n  if (segments.some(seg => seg === '.' || seg === '..')) {\n    throw new Error(`Invalid mount path: ${mountPath}. Path segments cannot be \".\" or \"..\".`);\n  }\n}\n\n/** Canonicalize mount path so `/data`, `/data/`, `//data` all resolve to `/data`. */\nfunction normalizeMountPath(mountPath: string): string {\n  return `/${mountPath.split('/').filter(Boolean).join('/')}`;\n}\n\n// =============================================================================\n// Local Sandbox\n// =============================================================================\n\n/**\n * Local sandbox provider configuration.\n */\nexport interface LocalSandboxOptions extends Omit<MastraSandboxOptions, 'processes'> {\n  /** Unique identifier for this sandbox instance */\n  id?: string;","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/workspace/sandbox/local-sandbox.ts#L54-L90","documentation":"validateMountPath rejects any path segment equal to `.` or `..`. Dot-dot segments could escape the intended mount namespace (path traversal), and `.` segments are ambiguous. Paths must be canonical — no relative traversal inside the mount point.","triggerScenarios":"Calling `sandbox.mount('/data/../etc')`, `sandbox.mount('/./data')`, or passing user input that includes `..` traversal; joining paths from untrusted config that contain `..`.","commonSituations":"Building mount paths from user-supplied subpaths without normalization; template strings like `/mnt/${name}` where name contains `..`; attempting to reach outside the sandbox root via traversal.","solutions":["Normalize the path first and reject it if any segment is `.` or `..` (or verify the normalized path still starts with the intended root)","Sanitize user input: strip or reject `..` sequences before constructing the mount path","Use path.resolve and confirm the result is under the allowed sandbox root"],"exampleFix":"// before\nsandbox.mount(`/data/${userSubdir}`); // userSubdir could be '../etc'\n// after\nconst seg = userSubdir.split('/').filter(Boolean);\nif (seg.some(s => s === '.' || s === '..')) throw new Error('Illegal path segment');\nsandbox.mount(`/data/${seg.join('/')}`);","handlingStrategy":"validation","validationCode":"function assertNoTraversal(p: string) {\n  const segs = p.split('/').filter(Boolean);\n  if (segs.some(s => s === '.' || s === '..')) throw new Error(`Path segment '.' or '..' not allowed in: ${p}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await sandbox.mount(`/data/${userSub}`);\n} catch (err) {\n  if (/segments cannot be/.test(String(err?.message))) {\n    throw new Error(`Refusing traversal in subpath: ${userSub}`);\n  }\n  throw err;\n}","preventionTips":["Treat any user-supplied path segment as untrusted: sanitize to [a-zA-Z0-9_.-] before joining","Reject '..' outright rather than normalizing it away — normalization can hide intent","Write a unit test that mounts with '../' inputs to lock in the rejection behavior"],"tags":["validation","security","path-traversal","mount"],"backgroundTag":"path-traversal-attempt","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}