Skip to content

Security: Unescaped commit hash in pull_upstream cherry-pick (CWE-78) #180

Description

@quangtran88

Summary

The pull_upstream tool interpolates the commit parameter directly into a git cherry-pick command with no escaping. While the policy engine's validate.git_hash rule validates commit format at the policy layer, defense-in-depth requires validation at execution time. A policy bypass or misconfigured rule would expose this injection point.

Vulnerable Code

if (commit) {
  await run(`git cherry-pick ${commit}`);
  appliedSummary = `Cherry-picked ${commit}`;
}

Recommendation

Validate at execution time with /^[a-f0-9]{7,40}$/ and use escapeShellArg():

if (!/^[a-f0-9]{7,40}$/.test(commit)) {
  return `Blocked: invalid commit hash "${commit}"`;
}
await run(`git cherry-pick -- ${escapeShellArg(commit)}`);

Severity: HIGH
CWE: CWE-78 (OS Command Injection)
Location: src/agent/tools.ts — line 511

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions