{"record":{"id":"d54aa1177f322b56","repo":"mastra-ai/mastra","slug":"invalid-file-path-filepath-absolute-paths-ar-d54aa1","errorCode":null,"errorMessage":"Invalid file path \"${filePath}\". Absolute paths are not allowed.","messagePattern":"Invalid file path \"(.+?)\"\\. Absolute paths are not allowed\\.","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/workspace.ts","lineNumber":1306,"sourceCode":"const SKILL_NAME_REGEX = /^[a-z0-9][a-z0-9-_]*$/i;\n\nfunction assertSafeSkillName(name: string): string {\n  if (!SKILL_NAME_REGEX.test(name)) {\n    throw new HTTPException(400, {\n      message: `Invalid skill name \"${name}\". Names must start with alphanumeric and contain only letters, numbers, hyphens, and underscores.`,\n    });\n  }\n  return name;\n}\n\n/**\n * Validate that a file path is safe (no traversal, no absolute paths).\n * Prevents malicious API responses from writing files outside the skill directory.\n */\nfunction assertSafeFilePath(filePath: string): string {\n  // Reject absolute paths\n  if (filePath.startsWith('/') || /^[a-zA-Z]:/.test(filePath)) {\n    throw new HTTPException(400, {\n      message: `Invalid file path \"${filePath}\". Absolute paths are not allowed.`,\n    });\n  }\n  // Reject path traversal attempts\n  const segments = filePath.split('/');\n  for (const segment of segments) {\n    if (segment === '..' || segment === '.') {\n      throw new HTTPException(400, {\n        message: `Invalid file path \"${filePath}\". Path traversal is not allowed.`,\n      });\n    }\n  }\n  return filePath;\n}\n\ninterface SkillFileEntry {\n  path: string;\n  content: string;","sourceCodeStart":1288,"sourceCodeEnd":1324,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/workspace.ts#L1288-L1324","documentation":"Thrown by assertSafeFilePath when a skill file path passed to the workspace skills mount endpoint is absolute (starts with '/' on POSIX or matches /^[a-zA-Z]:/ for drive letters on Windows). The server rejects absolute paths so a malicious or buggy API response cannot cause writes outside the target skill directory. It surfaces as an HTTPException with status 400.","triggerScenarios":"Calling the workspace install-skill/mount-skill endpoint with a file path like '/etc/passwd', 'C:\\evil\\file', or forwarding an unvalidated path field from a third-party skills API response into assertSafeFilePath.","commonSituations":"Proxies that pass client-supplied paths straight through; upstream skills registries returning absolute or Windows-style paths; tests or scripts hardcoding absolute local paths when calling the API.","solutions":["Pass a path relative to the skill directory (e.g. 'SKILL.md' or 'scripts/run.sh') instead of an absolute path.","Strip leading slashes or drive prefixes before calling the endpoint, or normalize the path client-side.","Verify the path actually came from the Skills API response and was not user-controlled input pasted into the request."],"exampleFix":"// before\nawait installSkill({ workspaceId, skillId, filePath: '/skills/foo/SKILL.md' });\n// after\nconst relative = '/skills/foo/SKILL.md'.replace(/^([a-zA-Z]:)?[\\\\/]+/, '');\nawait installSkill({ workspaceId, skillId, filePath: relative });","handlingStrategy":"validation","validationCode":"function isRelativeSafePath(p) {\n  return typeof p === 'string' && p.length > 0 && !p.startsWith('/') && !/^[a-zA-Z]:/.test(p);\n}\nif (!isRelativeSafePath(filePath)) throw new Error('Use a path relative to the skill directory');","typeGuard":"function isSafeRelativePath(p: unknown): p is string {\n  return typeof p === 'string' && !p.startsWith('/') && !/^[a-zA-Z]:/.test(p);\n}","tryCatchPattern":"try {\n  await installSkill({ workspaceId, filePath });\n} catch (e) {\n  if (String(e.message).includes('Absolute paths are not allowed')) {\n    filePath = filePath.replace(/^([a-zA-Z]:)?[\\\\/]+/, '');\n    await installSkill({ workspaceId, filePath });\n  } else throw e;\n}","preventionTips":["Always derive file paths from the Skills API listing instead of hand-building them.","Normalize paths with path.posix.normalize and strip drive/root prefixes before sending.","Never pass raw user input as a file path to workspace endpoints."],"tags":["path-validation","security","http-400","workspace"],"backgroundTag":"absolute-path-rejected","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}