CherryHQ/cherry-studio · error · Error

Invalid MCP package upload: file name cannot contain path se

Error message

Invalid MCP package upload: file name cannot contain path separators

What it means

Thrown by validatePackageUploadPayload when the trimmed filename contains a NUL byte or a forward/backward slash. The guard prevents the temp-file path (built as path.join(tempDir, `temp_file_${uuid}_${basename(fileName)}`)) from being influenced by separators in the renderer-supplied name. Although the code also runs path.basename on the name later, this check fails fast on any separator to give a clear message and to reject path-shaped input early.

Source

Thrown at src/main/ai/mcp/McpPackageService.ts:294

export function validatePackageUploadPayload(
  fileBuffer: ArrayBuffer | NodeJS.ArrayBufferView,
  fileName: string,
  packageFormat: McpPackageFormat
): Buffer {
  if (typeof fileName !== 'string') {
    throw new Error('Invalid MCP package upload: file name must be a string')
  }

  const trimmedFileName = fileName.trim()
  if (!trimmedFileName) {
    throw new Error('Invalid MCP package upload: file name cannot be empty')
  }
  if (trimmedFileName !== fileName) {
    throw new Error('Invalid MCP package upload: file name cannot contain leading or trailing whitespace')
  }
  if (trimmedFileName.includes('\0') || /[/\\]/.test(trimmedFileName)) {
    throw new Error('Invalid MCP package upload: file name cannot contain path separators')
  }
  if (!/^[A-Za-z0-9._ ()@+-]+$/.test(trimmedFileName)) {
    throw new Error('Invalid MCP package upload: file name contains unsupported characters')
  }
  if (path.extname(trimmedFileName).toLowerCase() !== `.${packageFormat}`) {
    throw new Error(`Invalid MCP package upload: expected a .${packageFormat} file`)
  }

  let buffer: Buffer
  if (fileBuffer instanceof ArrayBuffer) {
    buffer = Buffer.from(fileBuffer)
  } else if (ArrayBuffer.isView(fileBuffer)) {
    buffer = Buffer.from(fileBuffer.buffer, fileBuffer.byteOffset, fileBuffer.byteLength)
  } else {
    throw new Error('Invalid MCP package upload: file buffer must be an ArrayBuffer')
  }

  if (buffer.byteLength === 0) {

View on GitHub (pinned to 726446b54c)

Solutions

  1. On the renderer, send file.name (the base name) not file.path or any absolute path.
  2. If you only have a path, call path.basename (or split on the OS separator) before sending, but prefer the File.name API.
  3. Re-test the upload after the frontend change.

Example fix

// renderer - before
await upload(fileBuffer, droppedItem.path)  // full path like /home/u/x.pkg
// after
await upload(fileBuffer, droppedItem.name)  // base name only
Defensive patterns

Strategy: validation

Validate before calling

function isBaseFileName(fileName: string): boolean {
  return !fileName.includes('\0') && !/[/\\]/.test(fileName)
}

Type guard

function isBasenameOnly(s: unknown): s is string {
  return typeof s === 'string' && !s.includes('\0') && !/[/\\]/.test(s)
}

Prevention

When it happens

Trigger: Renderer sent fileName containing "/", "\", or \0: e.g. "subdir/pkg.mcpb", "C:\\Users\\x\\pkg.dxt", or a name with an embedded control character. Often the result of passing a full file path instead of just the base name.

Common situations: The renderer sent file.path (the full filesystem path of the selected File) instead of file.name; on some platforms drag-and-drop handlers yield the absolute path; a test fixture used path.join to build the filename.

Related errors


AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12). Data as JSON: /api/errors/ed6fe2e26e43c322. Report an issue: GitHub.