Skip to content

Conversation

@arthurbm
Copy link
Owner

@arthurbm arthurbm commented Jul 5, 2025

Fix Git status parsing logic, address command injection vulnerabilities, and enhance the setup wizard.

The Git status parsing bug incorrectly identified staged files as unstaged. The command injection vulnerability allowed unsanitized user input to be interpolated into shell commands. The setup wizard enhancements include improved API key validation, actual API call testing, better error handling, progress tracking, and additional language options, significantly improving the initial user experience and security.

cursoragent and others added 2 commits July 5, 2025 01:45
Co-authored-by: arthurmedeiros32 <arthurmedeiros32@gmail.com>
…p experience

Co-authored-by: arthurmedeiros32 <arthurmedeiros32@gmail.com>
@arthurbm arthurbm requested a review from Copilot July 5, 2025 01:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes three critical issues: corrects Git status parsing, prevents command injection in shell exports, and improves the interactive setup wizard with validation, testing, and progress tracking.

  • Refine parsing in getUnstagedChanges to only capture truly unstaged modifications
  • Escape and validate user inputs for API key and editor command to close injection vectors
  • Enhance gitlift init with real API/CLI/Git tests, progress summaries, and additional language options

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/core/git.ts Adjust Git status parsing logic to detect unstaged changes only
src/commands/init.ts Add input validation, shell-escape user values, implement configuration testing, and show setup progress and summary
Comments suppressed due to low confidence (1)

src/commands/init.ts:54

  • Add unit tests for the API key and editor command validation logic to ensure that edge cases and all validation branches produce the expected messages.
			validate: (input) => {

Comment on lines +255 to 259
if (trimmedLine.startsWith(" M")) {
// Only files modified in working tree but not staged
unstagedModifiedFiles.push(trimmedLine.substring(2).trim());
} else if (trimmedLine.startsWith("??")) {
untrackedFiles.push(trimmedLine.substring(2).trim());
Copy link

Copilot AI Jul 5, 2025

Choose a reason for hiding this comment

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

Using trimmedLine (which has no leading spaces) with .startsWith(" M") will never match. You should check the raw line or inspect characters by index before trimming, e.g., if (line.startsWith(' M')).

Suggested change
if (trimmedLine.startsWith(" M")) {
// Only files modified in working tree but not staged
unstagedModifiedFiles.push(trimmedLine.substring(2).trim());
} else if (trimmedLine.startsWith("??")) {
untrackedFiles.push(trimmedLine.substring(2).trim());
if (line.startsWith(" M")) {
// Only files modified in working tree but not staged
unstagedModifiedFiles.push(line.substring(2).trim());
} else if (line.startsWith("??")) {
untrackedFiles.push(line.substring(2).trim());

Copilot uses AI. Check for mistakes.

const exportLine = `\nexport OPENAI_API_KEY="${apiKey}"\n`;
// Properly escape the API key to prevent shell injection
const escapedApiKey = apiKey.replace(/'/g, "'\"'\"'");
Copy link

Copilot AI Jul 5, 2025

Choose a reason for hiding this comment

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

Consider using a dedicated shell-escaping library (e.g., shell-escape) instead of a custom replace to reliably handle all special characters and fully mitigate command injection risks.

Copilot uses AI. Check for mistakes.
const testPrompt = "test";
// Note: This would be a minimal API call to test connectivity
// For now, we'll just check if the key exists
if (!process.env.OPENAI_API_KEY) {
Copy link

Copilot AI Jul 5, 2025

Choose a reason for hiding this comment

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

[nitpick] Throwing on a missing API key stops the rest of the configuration tests (GitHub CLI, Git). Consider issuing a warning and continuing so users get full feedback on all checks.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants