diff options
| author | Octavian Guzu <oct@anthropic.com> | 2026-09-09 17:42:50 +0000 |
|---|---|---|
| committer | Octavian Guzu <oct@anthropic.com> | 2026-09-09 17:42:50 +0000 |
| commit | debbe686ab74ec095436a499b1a59864037e46cf (patch) | |
| tree | 849075bd62d15d2e938bc7938434fd4e1a893b88 /plugins/security-guidance/hooks/gitutil.py | |
| parent | f03d41e2c96f30b7b59a05566e998e6236a943e7 (diff) | |
Harden git invocation and repository hint handlingsg-resolve-repo-root
:house: Remote-Dev: homespace
Diffstat (limited to 'plugins/security-guidance/hooks/gitutil.py')
| -rw-r--r-- | plugins/security-guidance/hooks/gitutil.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/plugins/security-guidance/hooks/gitutil.py b/plugins/security-guidance/hooks/gitutil.py index de04bfeb..b6e8cd54 100644 --- a/plugins/security-guidance/hooks/gitutil.py +++ b/plugins/security-guidance/hooks/gitutil.py @@ -39,6 +39,29 @@ GIT_CMD = [ "-c", "core.quotePath=false", ] +SAFE_GIT_CONFIG = ( + ("core.fsmonitor", "false"), + ("core.hooksPath", "/dev/null"), +) + + +def git_config_env(pairs, base=None): + base = os.environ if base is None else base + try: + n = max(0, int(base.get("GIT_CONFIG_COUNT") or 0)) + except (TypeError, ValueError): + n = 0 + env = {} + for i, (k, v) in enumerate(pairs, start=n): + env[f"GIT_CONFIG_KEY_{i}"] = k + env[f"GIT_CONFIG_VALUE_{i}"] = v + env["GIT_CONFIG_COUNT"] = str(n + len(pairs)) + return env + + +def apply_safe_git_env(): + os.environ.update(git_config_env(SAFE_GIT_CONFIG)) + def _git_rev_parse_head(cwd): """Return the current HEAD SHA, or None if not a git repo / no commits.""" |
