fix: Properly escape file path in chmod command (#1527)#1732
Conversation
The chmod command was constructed with an unsanitized file path which could fail or be dangerous with special characters. This change wraps the path in single quotes and escapes any embedded single quotes with the standard '\'' technique. Fixes #1527 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryAdds proper shell escaping for file paths in the chmod command to prevent command injection vulnerabilities. Critical IssuesNone found ✅ AnalysisThe fix correctly addresses a command injection vulnerability in the chmod command execution: Why this fix is needed:
Why the fix is correct:
Why FromFile on line 33 doesn't need the same fix:
Verdict✅ APPROVE - No critical issues This is a good security fix that properly addresses command injection in the chmod execution path while correctly leaving the FromFile call unchanged (since it uses safe argument passing). |
There was a problem hiding this comment.
Pull request overview
This PR fixes a security and reliability issue in the FileInstaller.cs where file paths containing special shell characters (spaces, quotes, etc.) could cause the chmod command to fail or execute incorrectly. The fix properly escapes single quotes in file paths before interpolating them into a bash command string.
Key Changes
- Added shell escaping logic for file paths used in the
chmodcommand to prevent command injection and ensure paths with special characters work correctly - The path is now wrapped in single quotes with embedded single quotes escaped using the
'\''pattern
| } | ||
|
|
||
| await _bash.Command(new BashCommandOptions($"chmod u+x {options.Path}"), cancellationToken).ConfigureAwait(false); | ||
| var escapedPath = options.Path.Replace("'", "'\\''"); |
There was a problem hiding this comment.
The escaping logic is duplicated from the existing EscapeShellArgument utility method in PredefinedInstallers.cs (line 194). Consider extracting this method to a shared utility class to maintain consistency and follow the DRY principle. The existing method at PredefinedInstallers.cs:194-199 uses the same escaping pattern and includes documentation explaining the approach.
| var escapedPath = options.Path.Replace("'", "'\\''"); | |
| var escapedPath = PredefinedInstallers.EscapeShellArgument(options.Path); |
| var escapedPath = options.Path.Replace("'", "'\\''"); | ||
| await _bash.Command(new BashCommandOptions($"chmod u+x '{escapedPath}'"), cancellationToken).ConfigureAwait(false); |
There was a problem hiding this comment.
This fix for shell escaping lacks test coverage. The existing BashTests.cs file covers basic bash command execution but doesn't test file paths with special characters (spaces, quotes, etc.). Consider adding tests that verify the chmod command works correctly with file paths containing spaces and single quotes, as described in the PR test plan.
Summary
chmodcommand to fail or behave unexpectedly'\''Changes
Before:
After:
Test plan
/path/to/my script.sh)/path/to/it's working.sh)Fixes #1527
🤖 Generated with Claude Code