Skip to content

fix(security): the subprocess environment guard accepts the gh and kubectl keys that make a child run a program #2672

Description

@dan-petty

Problem Description

build_subprocess_env in src/devops_cli/core/process.py refuses a caller override that CONST_CODE_LOADING_ENV_PATTERNS matches. The patterns hold no key of gh or kubectl. #2633 found the same gap for the SSH_ keys and said that it did not claim these keys, because no probe of them ran. The probes below ran, and the gap is real.

  • GH_BROWSER names the program that gh browse starts to open a page.
  • A gh configuration directory (GH_CONFIG_DIR) can define an alias that starts with !. gh <alias> then runs that program. GH_CONFIG_DIR is already in CONST_GH_LOGIN_ENV_VARS.
  • A kubeconfig file (KUBECONFIG) can name an exec credential plugin. kubectl starts that program before its first request. KUBECONFIG is in DEFAULT_ALLOWED_ENV_VARS, and src/devops_cli/sandbox/kube_api.py gives it as a caller override.
  • Not probed, because each needs a terminal or a cluster: GH_EDITOR, GH_PAGER, KUBE_EDITOR and KUBECTL_EXTERNAL_DIFF. The manuals of gh and kubectl describe them as the program to run.

The keys of the second and third item name a file that callers set on purpose, so the fix is not one more pattern. The design must say which key the guard refuses, which key it accepts and why, as #2483 did for HOME and XDG_CONFIG_HOME.

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={"GH_BROWSER": "x", "GH_EDITOR": "x", "GH_PAGER": "x", "KUBE_EDITOR": "x", "KUBECTL_EXTERNAL_DIFF": "x", "KUBECONFIG": "x", "GH_CONFIG_DIR": "x"}) if k.startswith(("GH_", "KUBE"))))'.
  2. In a temporary directory <dir>, write an executable <dir>/marker that runs echo MARKER-RAN >&2; exit 1.
  3. Run env -i PATH=/usr/bin:/bin HOME=<dir> GH_TOKEN=fake-token-example GH_CONFIG_DIR=<dir>/cfg HTTPS_PROXY=http://127.0.0.1:9 GH_BROWSER=<dir>/marker gh browse -R example/example. The proxy points at a closed local port, so the command makes no request.
  4. In <dir>, write a kubeconfig whose user has exec.command set to <dir>/marker and interactiveMode: Never. Run env -i PATH=/usr/bin:/bin HOME=<dir> KUBECONFIG=<dir>/kubeconfig.yaml kubectl get ns.
  5. In <dir>/cfg2/config.yml, write an alias x: "!<dir>/marker". Run env -i PATH=/usr/bin:/bin HOME=<dir> GH_TOKEN=fake-token-example GH_CONFIG_DIR=<dir>/cfg2 HTTPS_PROXY=http://127.0.0.1:9 gh x.

Expected vs Actual Behavior

Expected: build_subprocess_env raises SecurityError for a caller override that makes gh or kubectl run a program that the caller names, or the design of the guard names each such key that it accepts and the reason.

Actual: step 1 returns all seven keys with no SecurityError. Steps 3, 4 and 5 each print MARKER-RAN, so the child runs the program.

Environment Diagnostics

  • DevOps CLI Version: main at ca9c1ad
  • Python Version: 3.14.10
  • OS & Architecture: Linux x86_64 (WSL2)
  • Execution Environment: DevContainer
  • gh 2.103.2 and kubectl v1.37.1

Logs, Traces, or Terminal Output

$ env -i ... GH_BROWSER=<dir>/marker gh browse -R example/example
MARKER-RAN <dir>/marker
$ env -i ... KUBECONFIG=<dir>/kubeconfig.yaml kubectl get ns
MARKER-RAN <dir>/marker
$ env -i ... GH_CONFIG_DIR=<dir>/cfg2 gh x
MARKER-RAN <dir>/marker

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: #2633

Proposed design

Problem statement

The subprocess environment guard in build_subprocess_env does not refuse caller overrides of GH_BROWSER, GH_EDITOR, GH_PAGER, KUBE_EDITOR, or KUBECTL_EXTERNAL_DIFF. Each key names a program that gh or kubectl executes, so a caller can make a child run an arbitrary program. The guard also does not document why it accepts GH_CONFIG_DIR and KUBECONFIG, which name files that can hold a program reference. The probes in the issue body confirm code execution through all three probed keys.

Acceptance criteria

Requirement: Refuse GH_BROWSER override

build_subprocess_env SHALL raise SecurityError when a caller override sets GH_BROWSER.

Scenario: Caller sets GH_BROWSER to a path

  • WHEN build_subprocess_env is called with env={"GH_BROWSER": "/tmp/evil"}
  • THEN SecurityError is raised with a message naming GH_BROWSER

Requirement: Refuse GH_EDITOR override

build_subprocess_env SHALL raise SecurityError when a caller override sets GH_EDITOR.

Scenario: Caller sets GH_EDITOR to a path

  • WHEN build_subprocess_env is called with env={"GH_EDITOR": "/tmp/evil"}
  • THEN SecurityError is raised with a message naming GH_EDITOR

Requirement: Refuse GH_PAGER override

build_subprocess_env SHALL raise SecurityError when a caller override sets GH_PAGER.

Scenario: Caller sets GH_PAGER to a path

  • WHEN build_subprocess_env is called with env={"GH_PAGER": "/tmp/evil"}
  • THEN SecurityError is raised with a message naming GH_PAGER

Requirement: Refuse KUBE_EDITOR override

build_subprocess_env SHALL raise SecurityError when a caller override sets KUBE_EDITOR.

Scenario: Caller sets KUBE_EDITOR to a path

  • WHEN build_subprocess_env is called with env={"KUBE_EDITOR": "/tmp/evil"}
  • THEN SecurityError is raised with a message naming KUBE_EDITOR

Requirement: Refuse KUBECTL_EXTERNAL_DIFF override

build_subprocess_env SHALL raise SecurityError when a caller override sets KUBECTL_EXTERNAL_DIFF.

Scenario: Caller sets KUBECTL_EXTERNAL_DIFF to a path

  • WHEN build_subprocess_env is called with env={"KUBECTL_EXTERNAL_DIFF": "/tmp/evil"}
  • THEN SecurityError is raised with a message naming KUBECTL_EXTERNAL_DIFF

Requirement: Accept GH_CONFIG_DIR override

build_subprocess_env SHALL accept a caller override of GH_CONFIG_DIR without raising SecurityError.

Scenario: Caller sets GH_CONFIG_DIR to a directory

  • WHEN build_subprocess_env is called with env={"GH_CONFIG_DIR": "/tmp/cfg"}
  • THEN The returned dict contains GH_CONFIG_DIR set to /tmp/cfg

Requirement: Accept KUBECONFIG override

build_subprocess_env SHALL accept a caller override of KUBECONFIG without raising SecurityError.

Scenario: Caller sets KUBECONFIG to a file path

  • WHEN build_subprocess_env is called with env={"KUBECONFIG": "/tmp/kubeconfig.yaml"}
  • THEN The returned dict contains KUBECONFIG set to /tmp/kubeconfig.yaml

Existing Tool Considered

No open, maintained tool or library covers this need. The guard is project-specific: it filters caller overrides against a project-defined constant. The change adds five exact key names to the existing CONST_CODE_LOADING_ENV_PATTERNS tuple, a design comment, and unit tests. Written cost: about 800 tokens to build, keep and fix, under one hour elapsed.

Key questions

  • Which of the seven keys does the guard refuse and which does it accept?: Refuse GH_BROWSER, GH_EDITOR, GH_PAGER, KUBE_EDITOR, KUBECTL_EXTERNAL_DIFF. Accept GH_CONFIG_DIR and KUBECONFIG. The five refused keys name a program directly and no caller in this codebase sets them. The two accepted keys name a file or directory that callers set on purpose, following the pattern of HOME and XDG_CONFIG_HOME in fix(security): the subprocess environment guard accepts the git keys that make a git child run a program #2483. (best practice) [sources: openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/design.md, openspec/changes/archive/2026-10-29-2633-refuse-ssh-code-env-keys/design.md:40, src/devops_cli/config/constants.py:1359, src/devops_cli/sandbox/kube_api.py]
    • Rejected: Refuse all seven keys. Rejected. GH_CONFIG_DIR is in CONST_GH_LOGIN_ENV_VARS and used by devcontainer.py. KUBECONFIG is in DEFAULT_ALLOWED_ENV_VARS and set by kube_api.py. Refusing them breaks the codebase's own callers.
    • Rejected: Refuse the five program-naming keys, accept the two file-naming keys. Chosen. The five refused keys name a program directly and no caller sets them. The two accepted keys name a file that callers set on purpose, matching the HOME and XDG_CONFIG_HOME precedent in fix(security): the subprocess environment guard accepts the git keys that make a git child run a program #2483.
    • Rejected: Accept all seven keys. Rejected. The probes in the issue body confirm code execution through GH_BROWSER, GH_CONFIG_DIR, and KUBECONFIG. Accepting the five program-naming keys leaves a confirmed code-execution path open.
  • Where does the guard check caller overrides?: The function _is_env_override_refused in src/devops_cli/core/process.py checks each caller override key against CONST_CODE_LOADING_ENV_PATTERNS using _is_env_var_denied, which runs fnmatch.fnmatchcase on the upper-case key. A key not in CONST_GIT_ACCEPTED_ENV that matches a pattern is refused. [sources: src/devops_cli/core/process.py]
  • Why does the guard accept GH_CONFIG_DIR?: GH_CONFIG_DIR is in CONST_GH_LOGIN_ENV_VARS (constants.py:1360) and is used by devcontainer.py:1268 to locate the gh config. A caller sets it to point gh at a specific configuration directory. This is the same case as HOME and XDG_CONFIG_HOME in fix(security): the subprocess environment guard accepts the git keys that make a git child run a program #2483: a caller must be able to give a child its own configuration directory. The risk that the config file holds a ! alias is acknowledged and accepted. (best practice) [sources: src/devops_cli/config/constants.py:1359, src/devops_cli/commands/devcontainer.py:1268, openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/design.md]
  • Why does the guard accept KUBECONFIG?: KUBECONFIG is in DEFAULT_ALLOWED_ENV_VARS and is set as a caller override by KubeApiRelay.env in kube_api.py to point kubectl at a relay kubeconfig with no credentials. A caller sets it to point kubectl at a specific kubeconfig file. This is the same case as HOME in fix(security): the subprocess environment guard accepts the git keys that make a git child run a program #2483: a caller must be able to give a child its own configuration file. The risk that the kubeconfig holds an exec credential plugin is acknowledged and accepted. (best practice) [sources: src/devops_cli/core/process.py, src/devops_cli/sandbox/kube_api.py, openspec/changes/archive/2026-10-29-2483-refuse-git-code-env-keys/design.md]
  • Does the fix(security): the subprocess environment guard accepts the ssh keys that make an ssh child run a program #2633 design already defer these keys to this issue?: Yes. The design of fix(security): the subprocess environment guard accepts the ssh keys that make an ssh child run a program #2633 states: 'The keys of gh and kubectl that name a program or a file with a program, for example GH_BROWSER, GH_CONFIG_DIR and KUBECONFIG: fix(security): the subprocess environment guard accepts the gh and kubectl keys that make a child run a program #2672. The probes of that issue ran a program with each of the three keys. Some of these keys name a file that callers set on purpose, so that issue needs its own design.' [sources: openspec/changes/archive/2026-10-29-2633-refuse-ssh-code-env-keys/design.md:40]

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 29, 2026
  2. dan-petty commented on Oct 29, 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 candidate fixes a security gap where environment keys let a child process run an arbitrary program.
    • Priority: P1-High. A caller can make a child execute an arbitrary program, which is a confirmed code-execution path.
    • Value: High. Closing this gap removes a path for arbitrary code execution in every subprocess the CLI spawns.
    • Effort: Medium. The fix needs a design decision for keys that name files callers set on purpose, plus pattern or allowlist changes and tests.
    • Related: fix(security): the subprocess environment guard accepts the git keys that make a git child run a program #2483, which asks for a different change. Both target build_subprocess_env in process.py for keys that let a child run a caller-named program, but #2483 covers git keys and this candidate covers gh and kubectl keys.
  3. added
    priority/p1-high
    on Oct 29, 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 c462318 (see proposed design in issue body).

  6. added
    type/bug
    scope/security
    status/in-progress
    and removed
    type/security
    status/ready
    on Oct 30, 2026
  7. removed
    status/in-progress
    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-highscope/securitysource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions