{"record":{"id":"5f955a751201a084","repo":"CherryHQ/cherry-studio","slug":"invalid-command-null-byte-detected","errorCode":null,"errorMessage":"Invalid command: null byte detected","messagePattern":"Invalid command: null byte detected","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ai/mcp/McpPackageService.ts","lineNumber":158,"sourceCode":"export 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 */\nexport function validateArgs(args: string[]): string[] {\n  if (!Array.isArray(args)) {\n    throw new Error('Invalid args: must be an array')\n  }\n","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/mcp/McpPackageService.ts#L140-L176","documentation":"Thrown by validateCommand() when the trimmed command string contains a null byte (\\0, U+0000). Null bytes are a classic injection vector: in C-based systems and some Node.js APIs, a null byte truncates the string at the byte boundary, so 'node\\0/etc/passwd' might be interpreted as just 'node' by the validator but as a different argument by the underlying process spawn. Rejecting null bytes prevents this mismatch.","triggerScenarios":"Called from resolveMcpConfig at line 351. Triggers when the manifest's command field or a variable-substituted result contains a \\0 character. This could come from raw binary data in a user_config value, a deliberately crafted manifest, or encoding corruption.","commonSituations":"A malicious manifest embeds a null byte to bypass downstream argument parsing; a binary file was accidentally read as a config value; encoding corruption from a cross-platform file transfer introduced null bytes; a user_config value sourced from an untrusted input contained raw bytes.","solutions":["Sanitize the command and all variable-substitution sources to strip null bytes before validation.","Audit user_config values to ensure they are clean text strings.","Do not install packages whose manifests contain null bytes — they are almost certainly malformed or malicious."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Strip null bytes before validation (if input is trusted)\nconst cleaned = command.replace(/\\0/g, '')\n// Or reject outright\nif (command.includes('\\0')) {\n  throw new Error('Command contains null bytes — refusing to execute')\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat null bytes in a command field as a security incident.","Sanitize all variable-substitution sources (user_config values) to strip null bytes.","Audit manifests for non-printable characters before installation."],"tags":["security","null-byte","mcp","command-injection","manifest"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}