CherryHQ/cherry-studio · error · Error
Invalid command: path traversal detected in "${command}"
Error message
Invalid command: path traversal detected in "${command}" What it means
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.
Source
Thrown at src/main/ai/mcp/McpPackageService.ts:153
*
* @param command - The command to validate
* @returns The validated command
* @throws Error if command contains path traversal or is invalid
*/
export function validateCommand(command: string): string {
if (!command || typeof command !== 'string') {
throw new Error('Invalid command: command must be a non-empty string')
}
const trimmed = command.trim()
if (!trimmed) {
throw new Error('Invalid command: command cannot be empty')
}
// Check for path traversal sequences
// This catches: .., ../, ..\, /../, \..\, etc.
if (/(?:^|[/\\])\.\.(?:[/\\]|$)/.test(trimmed) || trimmed === '..') {
throw new Error(`Invalid command: path traversal detected in "${command}"`)
}
// Check for null bytes
if (trimmed.includes('\0')) {
throw new Error('Invalid command: null byte detected')
}
return trimmed
}
/**
* Validate command arguments to prevent injection attacks.
* Rejects arguments containing path traversal sequences.
*
* @param args - The arguments array to validate
* @returns The validated arguments array
* @throws Error if any argument contains path traversal
*/View on GitHub (pinned to 726446b54c)
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.
Defensive patterns
Strategy: validation
Validate before calling
import path from 'node:path'
function hasPathTraversal(value: string): boolean {
return /(?:^|[/\\])\.\.(?:[/\\]|$)/.test(value) || value === '..'
}
if (hasPathTraversal(command)) {
throw new Error(`Command contains path traversal: ${command}`)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid command: null byte detected
- Invalid args: null byte detected in argument at index ${inde
- Invalid args: path traversal detected in argument at index $
- Path traversal detected: target path must be direct child of
- Unsafe DXT entry path (zip-slip): ${name}
AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12).
Data as JSON: /api/errors/9ea4a5b449231ea6.
Report an issue: GitHub.