From d82a004224539526143c5d8bd1b7780bcb07ec88 Mon Sep 17 00:00:00 2001 From: Terrasse Date: Wed, 27 Aug 2025 18:23:00 +0800 Subject: [PATCH] fix prompt injection bug --- server/claude-cli.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/server/claude-cli.js b/server/claude-cli.js index c8a5ebb..d6939af 100755 --- a/server/claude-cli.js +++ b/server/claude-cli.js @@ -25,15 +25,6 @@ async function spawnClaude(command, options = {}, ws) { // Build Claude CLI command - start with print/resume flags first const args = []; - // Add print flag with command if we have a command - if (command && command.trim()) { - - // Separate arguments for better cross-platform compatibility - // This prevents issues with spaces and quotes on Windows - args.push('--print'); - args.push(command); - } - // Use cwd (actual project directory) instead of projectPath (Claude's metadata directory) const workingDir = cwd || process.cwd(); @@ -225,6 +216,17 @@ async function spawnClaude(command, options = {}, ws) { console.log('📝 Skip permissions disabled due to plan mode'); } } + + // Add print flag with command if we have a command + if (command && command.trim()) { + + // Separate arguments for better cross-platform compatibility + // This prevents issues with spaces and quotes on Windows + args.push('--print'); + // Use `--` so user input is always treated as text, not options + args.push('--'); + args.push(command); + } console.log('Spawning Claude CLI:', 'claude', args.map(arg => { const cleanArg = arg.replace(/\n/g, '\\n').replace(/\r/g, '\\r');