{"record":{"id":"4909297806a624ce","repo":"mastra-ai/mastra","slug":"invalid-file-path-filepath-absolute-paths-ar","errorCode":null,"errorMessage":"Invalid file path \"${filePath}\". Absolute paths are not allowed.","messagePattern":"Invalid file path \"(.+?)\"\\. Absolute paths are not allowed\\.","errorType":"validation","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"packages/server/src/server/handlers/skills-sh-shared.ts","lineNumber":105,"sourceCode":"const SKILL_NAME_REGEX = /^[a-z0-9][a-z0-9-_]*$/i;\n\nexport function 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\n * directory.\n */\nexport function assertSafeFilePath(filePath: string): string {\n  if (filePath.startsWith('/') || 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  // Normalize backslashes to forward slashes so Windows-style traversal\n  // (e.g. \"..\\\\..\\\\etc\\\\passwd\") cannot bypass the segment check below.\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\n// =============================================================================\n// API calls","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/skills-sh-shared.ts#L87-L123","documentation":"A 400 security validation from `assertSafeFilePath`, rejecting any file path that is absolute: starts with '/' or '\\\\', or matches a Windows drive pattern like 'C:\\\\'. It prevents malicious upstream skill responses from writing outside the skill directory.","triggerScenarios":"Installing/downloading a skill whose manifest lists files with absolute paths (e.g. '/etc/passwd' or 'C:\\\\Windows\\\\x'), or constructing a file path yourself using an absolute base directory.","commonSituations":"A third-party skill in the registry publishes malicious absolute paths; joining an absolute base dir with a path that already starts with '/'; Windows-style paths pasted from another machine.","solutions":["Convert paths to relative form before sending: strip the leading '/' or drive prefix.","Reject or skip skills whose manifests contain absolute paths; report the skill as unsafe.","Compute relative paths with path.relative(baseDir, absolutePath) and verify the result doesn't escape the base.","Only install skills from trusted sources."],"exampleFix":"// before\nconst filePath = '/src/agent.ts';\nawait installSkillFile(skill, filePath);\n// after\nconst filePath = '/src/agent.ts'.replace(/^([a-zA-Z]:)?[\\\\/]+/, '');\nawait installSkillFile(skill, filePath); // \"src/agent.ts\"","handlingStrategy":"validation","validationCode":"if (/^([a-zA-Z]:)?[\\\\/]/.test(filePath)) throw new Error(`Path \"${filePath}\" must be relative to the skill directory.`);","typeGuard":null,"tryCatchPattern":"try {\n  await installSkill(skill);\n} catch (e) {\n  if (e instanceof MastraClientError && e.status === 400 && /Absolute paths are not allowed/.test(e.message)) {\n    console.error('Skill manifest contains an absolute path — treat the skill as untrusted and skip or report it.');\n  } else throw e;\n}","preventionTips":["Inspect third-party skill manifests for absolute paths before installing.","Build relative paths with path.relative(baseDir, target) instead of string concatenation.","Only install skills from trusted sources."],"tags":["security","path-traversal","http-400","skills"],"backgroundTag":"path-traversal-blocked","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}