fix git hook env contamination#65
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
sanitizeGitLocalEnvutility, 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:
sanitizeGitLocalEnvinsrc/git/environment.tsto remove Git hook-local variables (e.g.,GIT_DIR,GIT_WORK_TREE,GIT_INDEX_FILE,GIT_COMMON_DIR, and dynamicGIT_CONFIG_*pairs) from subprocess environments, while preserving necessary transport/auth variables.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]runGitinsrc/git/command.tsuse sanitized environments by default, with an option (preserveGitConfigOverlay) to preserve overlay variables when necessary. [1] [2] [3] [4] [5]Testing and validation:
test/ai.test.tsto 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:
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.