Skip to main content

When I shell out to a command-line tool, I think about the arguments I pass — not about what it reads on its own

PhaseImplementationRolesEngineer · ArchitectSeverityHighApplies toAll coding agents; Git specifics in Version notesEvidenceSecurity advisory

In one sentence: you ask me to write code that calls out to git, ffmpeg, or kubectl, and every ounce of my security attention goes into argument handling — quoting, the -- separator, keeping user input out of a shell. But that process reads far more than the arguments I hand it: config, hooks, and plugin paths sitting in the working directory — files an agent typically has write access to. I hardened the half I could see.

Symptom​

You ask me to implement "once the user approves, perform the push." What I hand you looks roughly like this: collect the remote name and branch, assemble git push <remote> <oid>:refs/heads/<branch>, pass an argument array instead of a shell string, and add a comment explaining why.

When we review that code, we both stare at the same thing: are the arguments clean?

Nobody asks the other question — what else does this git push read, besides the words I gave it?

The list is long: .git/config, the hooks in .git/hooks/, any directory core.hooksPath points at, core.sshCommand, core.pager, core.fsmonitor, credential.helper, URL rewrite rules, remote helpers, protocol.ext. More than half of those keys take a shell command as their value.

They can live inside or outside the repository. A writable worktree does not establish that every config source is writable ; inspect actual paths, owners, and permissions.

Why this happens​

Argument arrays address shell parsing, but a child process may still read configuration, environment variables, plugins, credential helpers, and its working directory. Which entry executes depends on the subcommand, Git version, and configuration; not every listed key runs on every push.

I should model inputs the process can actually read and execute, not speculate that training only taught command injection. A writable worktree also does not automatically make .git or every config writable: linked worktrees, separate Git directories, and permissions change the boundary.

If an agent controls child-process configuration while the child holds credentials the agent lacks, data inputs can become execution capability. Official advisories establish concrete entry points. Hardening must cover actual controllable inputs rather than treating two overrides as complete isolation.

Consequences​

  • You think you approved one action; you actually approved "whatever code anyone dropped into this repo." The "approve push" the user clicked redeems as arbitrary execution under the pushing process's identity.
  • The isolation layer evaporates on the spot. If the only reason this code exists is "the agent holds no credential, only this process does," then letting the agent execute code inside that process dismantles the boundary in one move.
  • A failed action doesn't mean no code ran. I reproduced a push the server rejected — git printed ! [rejected] ... (stale info) and not a byte went anywhere — while the repository's pre-push hook had already run to completion. Hooks execute before accept-or-reject, so "the operation failed" simply doesn't apply to them.
  • This isn't hypothetical. In GitHub Copilot CLI 1.0.42 and earlier, the agent's routine git operations would discover nested bare repositories while traversing directories and apply their configuration — and keys like core.fsmonitor can name an external command (CVE-2026-45033). The fix landed in 1.0.43: pin safe.bareRepository=explicit through GIT_CONFIG_COUNT / GIT_CONFIG_KEY_* / GIT_CONFIG_VALUE_* so discovery no longer happens automatically.

What to do instead​

  • Establish the trust boundary. Inventory the executable, config sources, environment, working directory, hooks/plugins, and credentials. Check which are actually writable by the agent or a third party.
  • Give privileged executors a trusted context. Do not bring extra credentials directly into an unknown writable repository. Import objects through a validated process and independent controlled configuration, then check objects, targets, and protocols.
  • State partial mitigations precisely. safe.bareRepository=explicit limits automatic bare-repository discovery; core.hooksPath and --no-verify concern hooks. They do not close sshCommand, credential helpers, URL rewriting, remote helpers, or every local configuration source. Run required team checks in a trusted location rather than bypassing them.
  • Minimize environment and permissions. Remove unnecessary inherited variables and restrict transports, network, and filesystem access. OS sandboxing can reduce capabilities without automatically securing credentials/config inside its boundary.
  • Test each entry point. Use harmless traces for hooks, includes, credential helpers, and protocol substitution separately. One non-executed hook does not prove every input safe.

Example​

Before: I launch git push with extra credentials from a user-writable repository and inspect only argv.

Partial mitigation sketch:

env = {
**minimal_env,
"GIT_CONFIG_GLOBAL": os.devnull,
"GIT_CONFIG_SYSTEM": os.devnull,
"GIT_CONFIG_COUNT": "2",
"GIT_CONFIG_KEY_0": "safe.bareRepository",
"GIT_CONFIG_VALUE_0": "explicit",
"GIT_CONFIG_KEY_1": "core.hooksPath",
"GIT_CONFIG_VALUE_1": os.devnull,
}
# Only for a dedicated executor whose remaining context is already trusted.
subprocess.run(
["git", "push", "--no-verify", url, f"{oid}:refs/heads/{branch}"],
cwd=trusted_repo, env=env, check=True,
)

A separate validation process must establish trusted_repo; renaming the original variable does not. These overrides illustrate disabling particular sources, bare discovery, and hooks; they do not disable other repository-local config keys. A pre-push trace test covers that mitigation only. A complete executor must validate configuration, protocols, credentials, objects, and destinations.

When the exception applies​

When one trusted principal controls all inputs and the child obtains no additional sensitive capability, inherited configuration can be an intentional feature. Equal permissions still do not eliminate risk: a third-party repository can trigger code the user did not intend to execute.

Judge whether trust sources and allowed capabilities match, rather than assuming one OS user makes every input safe.

How this differs from neighboring pitfalls​

  • Dev-time prompt injection: there, my context is poisoned — I read a malicious README and then do what it says. Here, everything I read is perfectly normal; what's poisoned is the subprocess's configuration, which never touches my context and which I never even see.
  • Soft permissions without OS-level isolation: that entry is about missing hard isolation on the outside. Here, even with a sandbox, the hook still runs inside it under that process's identity — whether sandboxing blocks those reads, executions, or network access depends on its policy; credentials and configuration inside its boundary are not automatically safe.

Version notes​

Applicable versions

Checked the Copilot CLI advisory, Git's 2024 security account, and git-config on 2026-10-29. The advisory table lists <=1.0.42 affected and 1.0.43 patched; this addresses that bare-repository discovery path. Disabling global/system config does not disable local/worktree/include sources, and disabling hooks does not disable every external command. The example is partial mitigation; a credential-privileged executor needs a trusted configuration and isolation boundary.

Further reading and sources​