File: packages/cli/src/index.ts
Lines: 323, 326, 329, 332
Severity: MEDIUM
Description:
The readPromptFile function (lines 337-368) accepts user-provided file paths via the --prompt-file flag and includes the raw path in error messages without sanitizing terminal control characters:
console.error(pc.red(`Prompt file not found: ${pc.bold(promptFile)}`));
console.error(pc.red(`Permission denied reading prompt file: ${pc.bold(promptFile)}`));
console.error(pc.red(`'${promptFile}' is a directory, not a file.`));
console.error(pc.red(`Error reading prompt file '${promptFile}': ${getErrorMessage(err)}`));
While the path is validated via validatePromptFilePath and validatePromptFileStats, these validators check for security properties (path traversal, symlinks) but don't strip ANSI escape sequences or terminal control characters.
If a user provides a malicious path containing ANSI escape sequences (e.g., --prompt-file $'\e[31mFAKE_ERROR\e[0m'), those sequences could be interpreted by the terminal, potentially:
- Displaying misleading error messages
- Hiding portions of the error output
- Causing terminal confusion in automated CI/CD environments
Attack Vector:
- User runs:
spawn claude sprite --prompt-file $'\e[2J\e[HMalicious Path'
- The
\e[2J\e[H ANSI codes clear the screen and move cursor to home
- Error message is displayed, but previous terminal output is cleared
Recommendation:
Sanitize file paths before inclusion in error messages by stripping control characters:
function sanitizePathForDisplay(path: string): string {
return path.replace(/[\x00-\x1F\x7F]/g, ''); // Strip ASCII control characters
}
// Usage:
const displayPath = sanitizePathForDisplay(promptFile);
console.error(pc.red(`Prompt file not found: ${pc.bold(displayPath)}`));
Alternatively, enhance validatePromptFilePath to reject paths containing control characters.
Impact:
Medium — Requires user to provide malicious input to their own CLI, but could affect automated systems parsing spawn output.
-- code-scanner
File: packages/cli/src/index.ts
Lines: 323, 326, 329, 332
Severity: MEDIUM
Description:
The
readPromptFilefunction (lines 337-368) accepts user-provided file paths via the--prompt-fileflag and includes the raw path in error messages without sanitizing terminal control characters:While the path is validated via
validatePromptFilePathandvalidatePromptFileStats, these validators check for security properties (path traversal, symlinks) but don't strip ANSI escape sequences or terminal control characters.If a user provides a malicious path containing ANSI escape sequences (e.g.,
--prompt-file $'\e[31mFAKE_ERROR\e[0m'), those sequences could be interpreted by the terminal, potentially:Attack Vector:
spawn claude sprite --prompt-file $'\e[2J\e[HMalicious Path'\e[2J\e[HANSI codes clear the screen and move cursor to homeRecommendation:
Sanitize file paths before inclusion in error messages by stripping control characters:
Alternatively, enhance
validatePromptFilePathto reject paths containing control characters.Impact:
Medium — Requires user to provide malicious input to their own CLI, but could affect automated systems parsing spawn output.
-- code-scanner