Skip to content

CLI-497 wrap hook command in quotes#545

Open
sophio-japharidze-sonarsource wants to merge 1 commit into
masterfrom
CLI-497_hook_command_paths_containing_special_chars
Open

CLI-497 wrap hook command in quotes#545
sophio-japharidze-sonarsource wants to merge 1 commit into
masterfrom
CLI-497_hook_command_paths_containing_special_chars

Conversation

@sophio-japharidze-sonarsource

@sophio-japharidze-sonarsource sophio-japharidze-sonarsource commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • Hook command quoting:
    • Wrapped hook script paths in quotes (" on Windows, ' on Unix) within resolveAgentHookCommand to support paths containing spaces or special characters.
    • Implemented quoteWindowsHookScriptPath to safely handle Windows paths in PowerShell.
    • Updated installHook in claude integration to use the new quoting logic.
  • Test infrastructure:
    • Added comprehensive unit and integration tests to verify quoted paths in shell environments, including handling of embedded apostrophes and directory spaces.
    • Added unquoteHookScriptPath helper to the test harness to allow reliable verification of quoted command strings.
    • Updated legacy test expectations to account for the new quoted format.

This will update automatically on new commits.

@netlify

netlify Bot commented Jul 2, 2026

Copy link
Copy Markdown

Deploy Preview for sonarqube-cli canceled.

Name Link
🔨 Latest commit 01aa866
🔍 Latest deploy log https://app.netlify.com/projects/sonarqube-cli/deploys/6a4b59e62ef05f00088dbfda

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Jul 2, 2026

Copy link
Copy Markdown

CLI-497

Comment thread src/cli/commands/integrate/_common/hooks.ts
@sophio-japharidze-sonarsource sophio-japharidze-sonarsource force-pushed the CLI-497_hook_command_paths_containing_special_chars branch from ed8d787 to 7e114c4 Compare July 2, 2026 15:26
@gitar-bot

gitar-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Wraps hook script paths in environment-specific quotes to support directory spaces and special characters. This change addresses the Windows meta-character vulnerability by implementing a robust quoting strategy.

✅ 1 resolved
Edge Case: Windows double-quoting does not neutralize $/% metacharacters

📄 src/cli/commands/integrate/_common/hooks.ts:132-140 📄 src/cli/commands/integrate/_common/hooks.ts:202-204
quoteWindowsHookScriptPath wraps the path in double quotes, and the doc comment justifies this by noting Windows paths cannot contain a double-quote character. That correctly handles spaces, but double quotes do NOT protect against other shell metacharacters that ARE legal in Windows path segments — e.g. a folder literally named %TEMP% (expanded by cmd.exe) or $foo (expanded by PowerShell). Depending on how the agent executes the stored command string (cmd.exe vs powershell), such a path could be altered. The Unix side is fully safe because shellQuoteBash uses single quotes, but the Windows side only guarantees space-safety. This is an unlikely edge case (paths with %/$ segments are rare) and mirrors pre-existing behavior, so it is minor — but the comment overstates the safety guarantee. Consider narrowing the comment to "safe against spaces" or escaping %/backtick if the target execution shell is known.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sophio-japharidze-sonarsource sophio-japharidze-sonarsource force-pushed the CLI-497_hook_command_paths_containing_special_chars branch from 7e114c4 to 543e276 Compare July 6, 2026 07:00
@sophio-japharidze-sonarsource sophio-japharidze-sonarsource force-pushed the CLI-497_hook_command_paths_containing_special_chars branch from 543e276 to 01aa866 Compare July 6, 2026 07:31
@sophio-japharidze-sonarsource sophio-japharidze-sonarsource marked this pull request as ready for review July 6, 2026 07:32
@gitar-bot

gitar-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Wraps hook command paths in OS-specific quotes to support spaces and special characters. This change resolves the previous issue with Windows metacharacter injection.

✅ 1 resolved
Edge Case: Windows double-quoting does not neutralize $/% metacharacters

📄 src/cli/commands/integrate/_common/hooks.ts:132-140 📄 src/cli/commands/integrate/_common/hooks.ts:202-204
quoteWindowsHookScriptPath wraps the path in double quotes, and the doc comment justifies this by noting Windows paths cannot contain a double-quote character. That correctly handles spaces, but double quotes do NOT protect against other shell metacharacters that ARE legal in Windows path segments — e.g. a folder literally named %TEMP% (expanded by cmd.exe) or $foo (expanded by PowerShell). Depending on how the agent executes the stored command string (cmd.exe vs powershell), such a path could be altered. The Unix side is fully safe because shellQuoteBash uses single quotes, but the Windows side only guarantees space-safety. This is an unlikely edge case (paths with %/$ segments are rare) and mirrors pre-existing behavior, so it is minor — but the comment overstates the safety guarantee. Consider narrowing the comment to "safe against spaces" or escaping %/backtick if the target execution shell is known.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqubecloud

sonarqubecloud Bot commented Jul 6, 2026

Copy link
Copy Markdown

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.

1 participant