fix: prevent command injection and fix cross-platform compatibility#19
fix: prevent command injection and fix cross-platform compatibility#19VivanRajath wants to merge 3 commits intoopen-gitagent:mainfrom
Conversation
shreyas-lyzr
left a comment
There was a problem hiding this comment.
Good intent — command injection prevention and cross-platform compat are important. However, there's a breaking change:
Build script change breaks macOS/Linux:
```diff
-"build": "tsc && cp src/voice/ui.html dist/voice/"
+"build": "tsc && copy src\voice\ui.html dist\voice\"
```
`copy` and backslash paths are Windows-only. This breaks the build on macOS and Linux (where all current contributors develop). Use a cross-platform approach:
```json
"build": "tsc && node -e "require('fs').cpSync('src/voice/ui.html','dist/voice/ui.html')""
```
The `execSync` → `execFileSync` changes and `path.sep` usage are correct and welcome. The `package-lock.json` diff includes unrelated dependency bumps — ideally separate those. Please fix the build script and I'll approve.
|
Thanks for the detailed review. I've updated the build script to use a cross-platform Node-based approach (using fs.cpSync) and ensured it works across macOS, Linux, and Windows. Also reverted the unrelated dependency changes in package-lock.json to keep this PR focused. tsc --noEmit passes with zero compilation errors |
fix: prevent command injection and fix cross-platform compatibility
Problem
Multiple files use
execSync()with string interpolation to run git commands. User-controlled inputs (branch names, commit messages, URLs) are interpolated directly into shell strings, enabling arbitrary command execution:Additionally:
cli,hooks,tool-loader) useshwhich doesn't exist on Windows, breaking core command execution on that platform./instead ofpath.sep, completely bypassing the security check on Windows (which uses\).Solution
1. Command Injection → Safe Argument Arrays
Replaced every
execSyncwith string interpolation withexecFileSyncusing argument arrays. Inputs are passed as separate OS-level arguments and are never interpreted by a shell:For compound git operations (e.g.,
git add && git commit), the single shell command was split into separateexecFileSynccalls:2. Cross-Platform Shell Execution
Shell-spawning tools now detect the platform and use the appropriate shell:
3. Path Traversal Guard Fix
Files Changed (12)
src/session.tsgit()helper rewritten + all 15 call sitessrc/loader.tsgit cloneinresolveInheritance()andresolveDependencies()src/index.tsisGitRepo(),ensureRepo()git init/add/commitsrc/tools/memory.tssrc/sandbox.tsgit remote get-url originsrc/tools/skill-learner.tsgitCommit()helper + delete actionsrc/tools/capture-photo.tssrc/plugin-cli.tsexecSyncimportsrc/tools/cli.tssh/cmd)src/hooks.tspath.sep) + cross-platform shellsrc/tool-loader.tsNot Included
src/voice/server.tsstill usesexecSync— it's a 113KB monolith that needs a refactor before these changes can be applied safely. Planned for a follow-up PR.Testing
-
tsc --noEmitpasses with zero compilation errors-
npm testpasses with zero compilation errors