Skip to content

harden(git): strip env-driven config-injection vectors + reject -c <override> in git wrapper #35

Closed

Description

@thehoff

Goal

Zero-trust layer on the git wrapper. LLM-driven shell calls inherit the parent env verbatim today, so anything that can set env vars (compromised dotfile, dirty CI runner, hostile postinstall) can steer subsequent contextcrawler git calls. We're not defending against active exploits — we're closing the inheritance gap so the agent can't be wagged by config it didn't author.

Pattern to mirror

src/core/utils.rs::secure_rg_command() + check_forbidden_rg_args() (PR #33).

Env vars to strip in secure_git_command()

Direct shell-exec hooks:
GIT_EXTERNAL_DIFF, GIT_SSH_COMMAND, GIT_SSH, GIT_PROXY_COMMAND, GIT_PAGER, GIT_EDITOR, GIT_SEQUENCE_EDITOR, GIT_ASKPASS, SSH_ASKPASS

Config-injection (the GIT_CONFIG_COUNT/_KEY_N/_VALUE_N family lets attacker set any config key including diff.external, core.fsmonitor, core.sshCommand, core.editor, core.gitProxy):
GIT_CONFIG, GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM, GIT_CONFIG_COUNT, GIT_CONFIG_KEY_*, GIT_CONFIG_VALUE_*, GIT_TEMPLATE_DIR, GIT_EXEC_PATH, GIT_HOOKS_PATH

Args to reject in check_forbidden_git_args()

  • -c key=val where key matches a denylist (diff.external, core.editor, core.pager, core.sshCommand, core.fsmonitor, core.gitProxy, core.hooksPath, core.gitProxy, safe.directory=*, protocol.*.allow, uploadpack.packObjectsHook). Allowlist by prefix is fine too.
  • --upload-pack=<cmd>, --receive-pack=<cmd> (HIGH)
  • --exec-path=<dir>
  • --git-dir=<...>, --work-tree=<...> (or restrict to project root)

Escape hatch

contextcrawler proxy git ... runs unwrapped for legitimate edge cases.

Tests (negative regression)

tests/security/git_hardening.rs:

  • Each stripped env var: invoke with the var set to a script that drops a marker file; assert marker NOT created.
  • Each rejected -c key: assert exit non-zero with the deny error.
  • Positive: git status, git log -3 --oneline still work.

Wire-in sites

  • src/cmds/git/git.rs (already uses resolved_command("git")) → switch to secure_git_command()
  • src/main.rs::Commands::Git { config_override } — drop config_override forwarding entirely OR validate against allowlist before forwarding
  • Any gh/glab/gt subcommands that internally shell to git — secondary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions