{"record":{"id":"9ea4a5b449231ea6","repo":"CherryHQ/cherry-studio","slug":"invalid-command-path-traversal-detected-in-com","errorCode":null,"errorMessage":"Invalid command: path traversal detected in \"${command}\"","messagePattern":"Invalid command: path traversal detected in \"(.+?)\"","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ai/mcp/McpPackageService.ts","lineNumber":153,"sourceCode":" *\n * @param command - The command to validate\n * @returns The validated command\n * @throws Error if command contains path traversal or is invalid\n */\nexport function validateCommand(command: string): string {\n  if (!command || typeof command !== 'string') {\n    throw new Error('Invalid command: command must be a non-empty string')\n  }\n\n  const trimmed = command.trim()\n  if (!trimmed) {\n    throw new Error('Invalid command: command cannot be empty')\n  }\n\n  // Check for path traversal sequences\n  // This catches: .., ../, ..\\, /../, \\..\\, etc.\n  if (/(?:^|[/\\\\])\\.\\.(?:[/\\\\]|$)/.test(trimmed) || trimmed === '..') {\n    throw new Error(`Invalid command: path traversal detected in \"${command}\"`)\n  }\n\n  // Check for null bytes\n  if (trimmed.includes('\\0')) {\n    throw new Error('Invalid command: null byte detected')\n  }\n\n  return trimmed\n}\n\n/**\n * Validate command arguments to prevent injection attacks.\n * Rejects arguments containing path traversal sequences.\n *\n * @param args - The arguments array to validate\n * @returns The validated arguments array\n * @throws Error if any argument contains path traversal\n */","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/mcp/McpPackageService.ts#L135-L171","documentation":"Thrown by validateCommand() when the trimmed command string contains path traversal sequences. The regex /(?:^|[/\\\\])\\.\\.(?:[/\\\\]|$)/ matches '..' when preceded by start-of-string or a path separator, and followed by a path separator or end-of-string. This catches '../', '..\\', '/../..\\', and a bare '..'. The check runs after the empty-string and null-byte checks.","triggerScenarios":"Called from resolveMcpConfig at line 351 after variable substitution. Triggers when the manifest's command contains traversal sequences like '../../../bin/sh', '../../etc/passwd', '..\\..\\Windows\\System32\\cmd.exe', or '/usr/../../../bin/sh'. These are classic path-traversal attack vectors in command execution.","commonSituations":"A malicious MCP package manifest embeds a traversal sequence in its command to escape the extraction directory and execute an arbitrary binary; a poorly constructed command path accidentally contains '..' segments; a platform_override was crafted to bypass the main command validation.","solutions":["Do not install or run the package — the command field contains a path-traversal attempt.","If the '..' is legitimate (e.g., a relative path within the package), use './' relative paths starting from extractDir instead.","Report the package to the MCP registry/marketplace as potentially malicious."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import path from 'node:path'\n\nfunction hasPathTraversal(value: string): boolean {\n  return /(?:^|[/\\\\])\\.\\.(?:[/\\\\]|$)/.test(value) || value === '..'\n}\n\nif (hasPathTraversal(command)) {\n  throw new Error(`Command contains path traversal: ${command}`)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat path-traversal in a command field as a security incident — the package may be malicious.","Use only simple command names (node, python, npx) or absolute paths without '..' segments.","Audit platform_overrides for traversal sequences — they bypass the main command field."],"tags":["security","path-traversal","mcp","command-injection","manifest"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}