Repository navigation
Description
Problem Description
build_subprocess_env in src/devops_cli/core/process.py refuses a caller override that matches CONST_CODE_LOADING_ENV_PATTERNS: the loader, gconv and bash keys (#2205, #2433). #2429 adds the zsh and interpreter keys. The guard accepts the git keys that make a git child run a program that its caller did not choose:
GIT_CONFIG_COUNTwithGIT_CONFIG_KEY_<n>andGIT_CONFIG_VALUE_<n>give git a configuration value. A value such ascore.fsmonitor,core.sshCommand,core.pageror an alias with!runs a program.GIT_SSH_COMMANDandGIT_SSHname the program that git starts for an SSH remote.GIT_CONFIG_GLOBALandGIT_CONFIG_SYSTEMname a configuration file.GIT_EXEC_PATHnames the directory of the git sub-programs.
DEFAULT_ALLOWED_ENV_VARS also lets the ambient GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM, GIT_EXEC_PATH, EDITOR and PAGER reach an isolated child. devops-cli sets some of these keys itself: src/devops_cli/config/constants.py gives git the override GIT_SSH_COMMAND=ssh -o BatchMode=yes. Thus the fix must decide which git keys a caller can set, and which the guard refuses. sudo refuses GIT_SSH_COMMAND and GIT_CONFIG_* in its default env_delete table (plugins/sudoers/env.c).
The design of #2429 keeps the git keys out of its scope, because #2429 is about the zsh and interpreter keys.
Reproduction Steps
- Run
uv run python -c 'from devops_cli.core.process import build_subprocess_env as b; print(sorted(k for k in b(env={"GIT_CONFIG_COUNT": "1", "GIT_CONFIG_KEY_0": "core.fsmonitor", "GIT_CONFIG_VALUE_0": "x", "GIT_SSH_COMMAND": "x"}) if k.startswith("GIT_")))'. - In a temporary directory
<dir>, rungit init -q <dir>/repo. - Run
env -i PATH=/usr/bin:/bin HOME=<dir> GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=core.fsmonitor GIT_CONFIG_VALUE_0='echo GIT-CONFIG-FSMONITOR-RAN >&2; false' git -C <dir>/repo status --short.
Expected vs Actual Behavior
Expected: build_subprocess_env raises SecurityError for a caller override of a git key that makes git run a program, or the design of the guard names each such key that it accepts and the reason.
Actual: step 1 returns the four keys with no SecurityError. Step 3 prints GIT-CONFIG-FSMONITOR-RAN, so git runs the program of the override.
Environment Diagnostics
- DevOps CLI Version: main at 960e357
- Python Version: 3.14.10
- OS & Architecture: Linux x86_64 (WSL2)
- Execution Environment: DevContainer
Logs, Traces, or Terminal Output
$ env -i PATH=/usr/bin:/bin HOME=<dir> GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=core.fsmonitor GIT_CONFIG_VALUE_0='echo GIT-CONFIG-FSMONITOR-RAN >&2; false' git -C <dir>/repo status --short # git 2.55.0
GIT-CONFIG-FSMONITOR-RAN
$ env -i PATH=/usr/bin:/bin HOME=<dir> GIT_CONFIG_GLOBAL=<dir>/gitconfig git -C <dir>/repo status --short # gitconfig sets core.fsmonitor
GIT-CONFIG-GLOBAL-RANPre-Submission Checklist
- I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
- I have checked existing issues and pull requests to ensure this is not a duplicate.
Source: #2429
Proposed design
Problem statement
The subprocess environment guard in build_subprocess_env accepts git environment variables that let a git child run a program the caller did not choose. A caller can set GIT_CONFIG_COUNT, GIT_CONFIG_KEY_, GIT_CONFIG_VALUE_, GIT_SSH_COMMAND, GIT_SSH, GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM, or GIT_EXEC_PATH to make git execute arbitrary code. The ambient allowlist also passes GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM, and GIT_EXEC_PATH to every isolated child.
Acceptance criteria
- Criterion 1: build_subprocess_env raises SecurityError when a caller override sets a git key that can make git run a program.
Verification: Run the reproduction command from the issue body. It must raise SecurityError instead of returning the four keys. - Criterion 2: DEFAULT_ALLOWED_ENV_VARS no longer includes GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM, or GIT_EXEC_PATH.
Verification: Import DEFAULT_ALLOWED_ENV_VARS and assert that none of the three keys is a member. - Criterion 3: devops-cli's own GIT_SSH_COMMAND and GIT_TERMINAL_PROMPT still reach a git child.
Verification: Run a git command through run_subprocess and assert that the child's environment holds GIT_SSH_COMMAND=ssh -o BatchMode=yes and GIT_TERMINAL_PROMPT=0. - Criterion 4: A test covers each denied git key and each safe git key.
Verification: Run the new tests. Each denied key raises SecurityError. Each safe key (GIT_AUTHOR_NAME, GIT_COMMITTER_EMAIL, GIT_TERMINAL_PROMPT) passes.
Key questions
- Which git environment keys must the guard deny for caller overrides?: Deny GIT_CONFIG_COUNT, GIT_CONFIG_KEY_, GIT_CONFIG_VALUE_, GIT_SSH_COMMAND, GIT_SSH, GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM, and GIT_EXEC_PATH. Keep GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL, and GIT_TERMINAL_PROMPT allowed. (best practice) [sources: src/devops_cli/config/constants.py, src/devops_cli/core/process.py]
- Chosen: Deny all git keys that can cause code execution. Chosen. sudo's env_delete refuses GIT_SSH_COMMAND and GIT_CONFIG_* (cited in the issue body). git documentation shows each key can run a program. The principle of least privilege applies.
- Rejected: Deny only GIT_CONFIG_COUNT, GIT_CONFIG_KEY_, GIT_CONFIG_VALUE_, and GIT_SSH_COMMAND. Rejected. GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM, and GIT_EXEC_PATH also cause code execution through a config file or a fake sub-program directory.
- Rejected: Deny every GIT_* key except a safe allowlist. Rejected. It is broader than needed and would block future safe git keys without a per-key review.
- How does devops-cli set its own GIT_SSH_COMMAND and GIT_TERMINAL_PROMPT after the guard denies them?: Set them in a post-guard step, following the existing pattern of _pin_github_token. The step runs after build_subprocess_env returns and writes the values directly into the child environment dict. (best practice) [sources: src/devops_cli/core/process.py, src/devops_cli/config/constants.py]
- Chosen: Post-guard step, like _pin_github_token. Chosen. The code already uses this pattern for GH_TOKEN. It keeps the guard strict and lets devops-cli set its own safe values after the check.
- Rejected: Add an internal bypass flag to build_subprocess_env. Rejected. A bypass flag weakens the guard for every caller and is harder to audit.
- Rejected: Keep GIT_SSH_COMMAND in the ambient allowlist and validate its value. Rejected. Value validation is fragile. A new ssh option or a different binary name can bypass it.
- Should EDITOR and PAGER stay in DEFAULT_ALLOWED_ENV_VARS?: Keep them in the ambient allowlist. They are general-purpose variables used by tools other than git. Deny them for caller overrides only when the child is a git command, or deny them for all caller overrides to keep the guard simple. (best practice) [sources: src/devops_cli/core/process.py]
- Chosen: Keep in ambient allowlist, deny for caller overrides. Chosen. Non-git tools may need them from the ambient environment. A caller override is the attack vector, so the guard denies it.
- Rejected: Remove from the ambient allowlist entirely. Rejected. It breaks non-git tools that read EDITOR or PAGER from the environment.
- Does the guard already cover the git keys through CONST_CODE_LOADING_ENV_PATTERNS?: No. CONST_CODE_LOADING_ENV_PATTERNS covers loader, gconv, bash, zsh, and interpreter keys. It has no git entries. The git keys pass the guard unchecked. [sources: src/devops_cli/config/constants.py]
- Does devops-cli set GIT_SSH_COMMAND itself?: Yes. CONST_GIT_NONINTERACTIVE_ENV in constants.py sets GIT_SSH_COMMAND to ssh -o BatchMode=yes and GIT_TERMINAL_PROMPT to 0. [sources: src/devops_cli/config/constants.py]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Oct 28, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
The guard accepts git keys that let a child process run an arbitrary program, which is a code-execution security gap.A caller can trigger arbitrary program execution in a git child via accepted environment keys.Closing the gap removes a code-execution vector in the security boundary.Requires identifying all dangerous git keys, updating the guard, handling tool-set keys, and adding tests.Both target the subprocess environment guard in process.py, but #41 established the isolation while this candidate fixes a gap where git execution keys pass the guard.fix(security): the subprocess environment guard refuses the zsh and i…
devops-cli-service commentedon Oct 29, 2026
Status set to Ready at d156ce7 (see proposed design in issue body).
test(security): use tmp_path, not a /tmp literal, in the git key test (…
fix(security): refuse the git keys that make git run a program (#2641)
chore(main): release 0.16.2 (#2649)
fix(security): refuse the library keys that load a module (#2682)
fix(security): refuse the gh and kubectl keys that run a program (#2732)