Skip to content

fix git hook env contamination#65

Merged
dbrosio3 merged 3 commits into
mainfrom
codex/fix-git-hook-env-contamination-2
Jun 27, 2026
Merged

fix git hook env contamination#65
dbrosio3 merged 3 commits into
mainfrom
codex/fix-git-hook-env-contamination-2

Conversation

@dbrosio3

Copy link
Copy Markdown
Member

This pull request addresses a critical safety and correctness issue by ensuring that Git hook-local environment variables do not leak into subprocesses launched by Pushgate, which could otherwise corrupt repository state or cause unintended side effects. The main change is the introduction of the sanitizeGitLocalEnv utility, which strips sensitive Git environment variables from subprocess environments, with targeted application across all relevant subprocess invocations, including AI providers, plugins, and configured tools. Extensive tests have been added to guarantee that the environment is sanitized as intended, and an implementation note has been added to the documentation.

Environment variable sanitization and safety:

  • Introduced sanitizeGitLocalEnv in src/git/environment.ts to remove Git hook-local variables (e.g., GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, GIT_COMMON_DIR, and dynamic GIT_CONFIG_* pairs) from subprocess environments, while preserving necessary transport/auth variables.
  • Updated all subprocess invocations for AI providers (src/ai/providers/claude.ts, src/ai/providers/run-provider-command.ts), Gitleaks plugin (src/runner/plugins/gitleaks.ts), and configured tools (src/runner/tool-command.ts) to use sanitized environments. [1] [2] [3] [4] [5] [6] [7] [8]
  • Ensured all internal Git helper invocations via runGit in src/git/command.ts use sanitized environments by default, with an option (preserveGitConfigOverlay) to preserve overlay variables when necessary. [1] [2] [3] [4] [5]

Testing and validation:

  • Updated and expanded tests in test/ai.test.ts to verify that AI provider subprocesses receive sanitized environments, including regression and acceptance tests for environment variable leakage. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15]

Documentation:

  • Added a new documentation file, docs/fix-git-hook-env-contamination.md, describing the problem, the implemented fix, and test/acceptance plans.

These changes collectively ensure that Pushgate subprocesses are protected from accidental repository corruption or interference caused by inherited Git hook-local environment variables.

@dbrosio3 dbrosio3 merged commit fdb1604 into main Jun 27, 2026
1 check passed
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.

1 participant