Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils/commandExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function executeCommand(

const childProcess = spawn(command, args, {
env: process.env,
shell: false,
shell: true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Enabling shell: true unconditionally can introduce security vulnerabilities if the command or arguments are not properly sanitized, especially on non-Windows platforms where it might not be necessary. Since this change is intended for Windows compatibility, it's safer to enable the shell only when running on Windows. This minimizes the potential attack surface of command injection.

Suggested change
shell: true,
shell: process.platform === "win32",

stdio: ["ignore", "pipe", "pipe"],
});

Expand Down
24 changes: 8 additions & 16 deletions src/utils/geminiExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,12 @@ ${prompt_processed}
prompt_processed = changeModeInstructions;
}

const args = [];
const args = ['-y']; // YOLO mode for non-interactive
if (model) { args.push(CLI.FLAGS.MODEL, model); }
if (sandbox) { args.push(CLI.FLAGS.SANDBOX); }

// Ensure @ symbols work cross-platform by wrapping in quotes if needed
const finalPrompt = prompt_processed.includes('@') && !prompt_processed.startsWith('"')
? `"${prompt_processed}"`
: prompt_processed;

args.push(CLI.FLAGS.PROMPT, finalPrompt);

// Use positional prompt (not -p flag which is deprecated)
args.push(prompt_processed);
Comment on lines +91 to +96

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for constructing the arguments array is nearly identical here and in the catch block (lines 104-111). This duplication can lead to maintenance issues, where a change in one place might not be reflected in the other. To improve maintainability and reduce redundancy, consider extracting this logic into a single helper function.


try {
return await executeCommand(CLI.COMMANDS.GEMINI, args, onProgress);
Expand All @@ -105,18 +101,14 @@ ${prompt_processed}
if (errorMessage.includes(ERROR_MESSAGES.QUOTA_EXCEEDED) && model !== MODELS.FLASH) {
Logger.warn(`${ERROR_MESSAGES.QUOTA_EXCEEDED}. Falling back to ${MODELS.FLASH}.`);
await sendStatusMessage(STATUS_MESSAGES.FLASH_RETRY);
const fallbackArgs = [];
const fallbackArgs = ['-y']; // YOLO mode
fallbackArgs.push(CLI.FLAGS.MODEL, MODELS.FLASH);
if (sandbox) {
fallbackArgs.push(CLI.FLAGS.SANDBOX);
}

// Same @ symbol handling for fallback
const fallbackPrompt = prompt_processed.includes('@') && !prompt_processed.startsWith('"')
? `"${prompt_processed}"`
: prompt_processed;

fallbackArgs.push(CLI.FLAGS.PROMPT, fallbackPrompt);

// Use positional prompt
fallbackArgs.push(prompt_processed);
try {
const result = await executeCommand(CLI.COMMANDS.GEMINI, fallbackArgs, onProgress);
Logger.warn(`Successfully executed with ${MODELS.FLASH} fallback.`);
Expand Down