Skip to content

The agent that grows with you

fix(cli): pin core.sshCommand to BatchMode ssh in the noninteractive git env

liuhao10249f0bf22ce2e6
diff --git a/hermes_cli/_subprocess_compat.py b/hermes_cli/_subprocess_compat.py
index a994de62391..95918e91a4a 100644
--- a/hermes_cli/_subprocess_compat.py
+++ b/hermes_cli/_subprocess_compat.py
@@ -224,6 +224,11 @@ _GIT_CONFIG_OVERRIDES = {
"core.editor": "true",
"sequence.editor": "true",
"diff.external": "",
+ # ssh itself bypasses stdin=DEVNULL/GIT_TERMINAL_PROMPT and opens /dev/tty directly — an
+ # unknown host key (or password auth) prompts there and steals the caller's terminal (#104591).
+ # BatchMode makes ssh fail instead of prompting; a working ssh-agent still succeeds. Injected
+ # at the config layer so an explicit user GIT_SSH_COMMAND (env) still takes precedence.
+ "core.sshCommand": "ssh -o BatchMode=yes",
}
@@ -234,8 +239,12 @@ def noninteractive_git_env(base: "Mapping[str, str] | None" = None) -> dict[str,
prompting), ``GCM_INTERACTIVE=Never`` (no Git Credential Manager dialog), and isolated git
config: inherited ``GIT_CONFIG_*`` injection, global/system config, pagers, editors, fsmonitor,
external diff and hooks are all disabled so a user's repo/global config cannot hang or mutate
- Hermes's plumbing calls. ``GIT_ASKPASS``/``SSH_ASKPASS`` are deliberately left alone: a
- *working* askpass helper or ssh-agent should still succeed non-interactively. Pair with
+ Hermes's plumbing calls. ``core.sshCommand`` is pinned to ``ssh -o BatchMode=yes`` so the ssh
+ child of a fetch/ls-remote fails instead of prompting — ssh bypasses ``stdin=DEVNULL`` and
+ opens ``/dev/tty`` directly (#104591); an agent-authenticated ssh still succeeds, and an
+ explicit user ``GIT_SSH_COMMAND`` env var still takes precedence over this config-layer pin.
+ ``GIT_ASKPASS``/``SSH_ASKPASS`` are deliberately left alone: a *working* askpass helper or
+ ssh-agent should still succeed non-interactively. Pair with
``stdin=subprocess.DEVNULL``. Internal plumbing only — the agent-facing terminal tool has its
own policy layer and visible PTY.
diff --git a/tests/hermes_cli/test_noninteractive_git.py b/tests/hermes_cli/test_noninteractive_git.py
index 04843413c1a..7579f463e2a 100644
--- a/tests/hermes_cli/test_noninteractive_git.py
+++ b/tests/hermes_cli/test_noninteractive_git.py
@@ -97,6 +97,24 @@ class TestNoninteractiveGitEnv:
assert values["sequence.editor"] == "true"
assert values["diff.external"] == ""
+ def test_ssh_host_key_prompts_fail_closed(self):
+ """core.sshCommand is pinned to BatchMode ssh (#104591).
+
+ ssh bypasses ``stdin=DEVNULL`` and ``GIT_TERMINAL_PROMPT`` — an unknown host key (or
+ password auth) opens ``/dev/tty`` directly and steals the caller's terminal. Under this
+ env the ssh child of a git fetch must fail fast instead of prompting; an
+ agent-authenticated ssh still succeeds.
+ """
+ env = noninteractive_git_env({})
+ values = {
+ env[f"GIT_CONFIG_KEY_{idx}"]: env[f"GIT_CONFIG_VALUE_{idx}"]
+ for idx in range(int(env["GIT_CONFIG_COUNT"]))
+ }
+ assert values["core.sshCommand"] == "ssh -o BatchMode=yes"
+ # Config-layer pin only: GIT_SSH_COMMAND is never set or overridden here, so a user's
+ # explicit env var still takes precedence over core.sshCommand.
+ assert env.get("GIT_SSH_COMMAND") == os.environ.get("GIT_SSH_COMMAND")
+
# ---------------------------------------------------------------------------
# 2. Real-git E2E: 401 remote fails fast instead of prompting