Skip to content

Remove shell expansion for git commands#447

Merged
dkundel-openai merged 2 commits into
mainfrom
bryane/git-remove-shell-expansion
Jul 8, 2026
Merged

Remove shell expansion for git commands#447
dkundel-openai merged 2 commits into
mainfrom
bryane/git-remove-shell-expansion

Conversation

@bryane-oai

Copy link
Copy Markdown
Contributor

Summary

Ensure Git commands are executed directly on Windows instead of being routed through a shell.

Git reference names can contain characters that Windows shells interpret specially. Passing those references through shell: true can therefore change the meaning of an otherwise valid Git command. This change keeps Git arguments as a literal argv array by forcing shell: false in the shared Git helpers.

Historical context

Windows npm installations expose tools such as npm and codex through .cmd shims, which Node cannot launch directly in some configurations.

  • #13 enabled shell: true for the shared synchronous command runner so Windows could resolve those shims.
  • #55 added equivalent handling for the Codex app-server process, along with hidden-window and process-tree cleanup behavior.
  • #178 made Windows launches respect SHELL, preserving compatibility with Git Bash.

Those changes fixed important Windows behavior, but the shared command runner also handles Git. Unlike npm and codex, Git is directly executable on Windows and does not need shell-based .cmd resolution.

Changes

  • Allow callers of runCommand to override its shell setting.
  • Force shell: false in both Git command helpers.
  • Apply the Git override after caller-provided options so it cannot be re-enabled accidentally.
  • Add regression coverage for an automatically detected default branch containing shell-special characters.
  • Update the test command helper to support an explicit shell setting when constructing the fixture.

The regression test verifies that the branch name is passed to Git literally and that an adjacent command helper is not executed.

Compatibility

The existing Windows behavior remains unchanged for commands that require it:

  • npm and Codex .cmd discovery continues to use the configured Windows shell.
  • Codex app-server startup continues to respect SHELL for Git Bash users.
  • Existing Windows process-tree cleanup and hidden-window behavior are unaffected.
  • macOS and Linux behavior is unchanged.

This approach avoids restricting valid Git reference names and confines the change to the command path that does not require shell expansion.

Validation

  • npm test: 91 tests passed
  • Focused Git tests: 11 tests passed
  • git diff --check: clean

@bryane-oai
bryane-oai requested a review from a team July 7, 2026 23:18
@dkundel-openai
dkundel-openai merged commit db52e28 into main Jul 8, 2026
1 check passed
HerbertGao added a commit to HerbertGao/codex-plugin-cc that referenced this pull request Jul 8, 2026
- v1.0.6 (PR openai#447): git commands no longer pass through a shell (shell: false)
- Resolved version conflicts to 1.0.6-herbertgao.1 (fork suffix convention)
- Preserved fork's codex-rescue foreground-forcing customization (untouched by v1.0.6)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
DKalien added a commit to DKalien/codex-plugin-cc that referenced this pull request Jul 8, 2026
- Merge upstream security fix: remove shell expansion for git commands (openai#447)
- Add options.shell override support in runCommand
- Update version to 1.0.6.1
- Keep local Node.js v25 compatibility improvements
Jafee added a commit to Jafee/codex-plugin-cc-stable that referenced this pull request Jul 8, 2026
Port of openai/codex-plugin-cc v1.0.6 (net diff 80c31f9..db52e28, PR openai#447).
On win32 runCommand defaulted to shell: process.env.SHELL || true, so
git()/gitChecked() ran repository-derived arguments (baseRef, branch
names, paths) through cmd.exe or the user's shell — a malicious repo
could inject commands via a crafted default-branch name. git commands
now force shell: false (after the options spread, so callers cannot
override it back); runCommand and the test helper honor an explicit
options.shell via ?? while keeping the old platform default otherwise.
Regression test: a branch named main&branch-helper&x must reach git
literally and never execute the repo-local branch-helper.cmd.

Fork notes: tests/helpers.mjs merged with the fork's timeout option;
upstream version hunks replaced by the fork's own versioning. This
supersedes HOLD item openai#294 (same root cause, fixed at the source).

Dual review: Claude (Fable 5) APPROVE + Codex (gpt-5.5 xhigh, fresh
read-only, pinned-SHA static audit) APPROVE. Clean-env suite 124/124.

Co-Authored-By: bryane-oai <bryane@openai.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Crazytieguy added a commit to Crazytieguy/codex-plugin-cc that referenced this pull request Jul 9, 2026
…ture

Adopted:
- Remove shell expansion for git commands (upstream openai#447): git spawns now
  pass shell: false via an options.shell passthrough in lib/process.mjs
  and tests/helpers.mjs, composed with our resolveWindowsShell() on win32.
  Includes upstream's regression test for branch names with shell
  metacharacters.
- app-server.mjs: append captured stderr to "app-server exited
  unexpectedly" errors.

Rejected:
- /codex:transfer Claude-session-to-Codex-thread feature (upstream openai#374):
  transferring Claude-generated assistant turns into a Codex thread puts
  Codex out of distribution; also couples to Codex's private import ledger.
  All transfer code, command, protocol types, fixtures, and tests dropped.
- Upstream version bumps and identity churn (package.json, marketplace,
  plugin.json, README) per fork policy.

Post-merge fixes:
- Dropped upstream's requestAttestation: false capability — the checked-in
  generated InitializeCapabilities type doesn't define it, so it broke the
  tsc build (found by Codex review).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LE4prC9U5Snku24TXbUfYr
AK25789 added a commit to AK25789/mx-codex4ada that referenced this pull request Jul 15, 2026
Same hardening upstream applied to the codex commands (openai#168/openai#447 family):
unquoted $ARGUMENTS is subject to shell word-splitting and glob expansion.
Found by Mira during the pre-rebase consultation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
zknpr added a commit to zknpr/codex-plugin-cc that referenced this pull request Jul 16, 2026
Brings the branch onto v1.0.6: session transfer (openai#374), 1.0.5/1.0.6 bumps,
and no-shell-expansion for git commands (openai#447). Conflicts resolved in
codex-companion.mjs (workspace-boundary notice + transfer dispatch coexist)
and lib/app-server.mjs (child exit deregisters the host-exit reaper AND
carries captured stderr in protocol errors). Full suite green: 124/124.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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