Skip to content

fix(security): the subprocess environment guard accepts the git keys that make a git child run a program #2483

Description

@dan-petty

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_COUNT with GIT_CONFIG_KEY_<n> and GIT_CONFIG_VALUE_<n> give git a configuration value. A value such as core.fsmonitor, core.sshCommand, core.pager or an alias with ! runs a program.
  • GIT_SSH_COMMAND and GIT_SSH name the program that git starts for an SSH remote.
  • GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM name a configuration file. GIT_EXEC_PATH names 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

  1. 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_")))'.
  2. In a temporary directory <dir>, run git init -q <dir>/repo.
  3. 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-RAN

Pre-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

  1. added
    source/agent
    type/security
    status/new
    value/high
    effort/medium
    on Oct 28, 2026
  2. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/security. The guard accepts git keys that let a child process run an arbitrary program, which is a code-execution security gap.
    • Priority: P1-High. A caller can trigger arbitrary program execution in a git child via accepted environment keys.
    • Value: High. Closing the gap removes a code-execution vector in the security boundary.
    • Effort: Medium. Requires identifying all dangerous git keys, updating the guard, handling tool-set keys, and adding tests.
    • Related: feat(security): subprocess environment isolation and credential boundary #41, which asks for a different change. 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.
  3. added
    priority/p1-high
    on Oct 28, 2026
  4. added
    status/ready
    and removed
    status/new
    on Oct 29, 2026
  5. devops-cli-service commented on Oct 29, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at d156ce7 (see proposed design in issue body).

  6. added a commit that references this issue on Oct 29, 2026
    b4b1277
  7. removed
    status/ready
    on Oct 30, 2026
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

    effort/mediumpriority/p1-highsource/agenttype/securityvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions