Skip to content

fix(security): the subprocess environment guard accepts the uv and npm keys that make a child run a program #2673

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 (#2205, #2429, #2483). It accepts keys of other tools that name a program for the child to start. Two probes found such keys in tools that devops-cli starts:

  • UV_PYTHON names the Python interpreter that uv run starts. uv starts the program of the key to ask it for its version. The prefix UV_ is in DEFAULT_ALLOWED_ENV_PREFIXES (perf(ci): pytest start-up and collection on the GitHub runner take half of today's 45 seconds #1735), so the key also reaches an isolated child from the environment.
  • npm_config_script_shell names the shell that npm run starts for each script. npm_config_node_options and npm_config_userconfig are keys of the same family. src/devops_cli/commands/install_tools.py sets other npm_config_* keys as caller overrides, so a pattern for the whole family cannot work.

The Go toolchain has a key of the same kind: the page of go help build says that -toolexec makes go run a program of the caller in place of the compiler tools, and GOFLAGS can carry the flag. go is not in the devcontainer, so no probe of the Go keys ran.

The change for #2503 refuses the keys of libraries that load a module. It does not claim these keys: they name a program, not a module, and each tool needs its own decision.

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={"UV_PYTHON": "x", "npm_config_script_shell": "x"}) if k.lower().startswith(("uv_python", "npm_config_script")))'.
  2. In a temporary directory <dir>, write an executable <dir>/fake-python that appends the line FAKE-PYTHON-RAN to <dir>/marker and then runs /usr/bin/python3 "$@".
  3. In <dir>, run env -i PATH=/usr/local/bin:/usr/bin:/bin HOME=<dir> UV_CACHE_DIR=<dir>/cache UV_PYTHON=<dir>/fake-python uv run --no-project --offline python -c pass. Then read <dir>/marker.
  4. In a second directory with a package.json that has the script t (echo hi), write an executable fake-sh that appends FAKE-SH-RAN to a marker and then runs /bin/sh "$@". Run env -i PATH=<node dir>:/usr/bin:/bin HOME=<dir> npm_config_script_shell=<path of fake-sh> npm run t.

Expected vs Actual Behavior

Expected: build_subprocess_env raises SecurityError for a caller override of a key that makes uv, npm or go start 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 both keys with no SecurityError. Step 3 writes FAKE-PYTHON-RAN and step 4 writes FAKE-SH-RAN, so each child starts the program of the override.

Environment Diagnostics

  • DevOps CLI Version: main at 5bb1ed0
  • Python Version: 3.14.10
  • OS & Architecture: Linux x86_64 (WSL2)
  • Execution Environment: DevContainer

Logs, Traces, or Terminal Output

$ env -i ... UV_PYTHON=<dir>/fake-python uv run --no-project --offline python -c pass   # uv 0.12.23
$ cat <dir>/marker
FAKE-PYTHON-RAN
$ env -i ... npm_config_script_shell=<dir>/fake-sh npm run t                           # npm 11.19.1
$ cat <marker of fake-sh>
FAKE-SH-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.

Proposed design

Problem statement

The subprocess environment guard in build_subprocess_env refuses caller overrides that match CONST_CODE_LOADING_ENV_PATTERNS, which covers keys that make a child load code. It accepts keys that make a tool start a caller-named program. Probes confirmed that UV_PYTHON, npm_config_script_shell, and VIRTUAL_ENV each let a caller start an arbitrary program in a child process. GOFLAGS can carry the -toolexec flag for the same effect.

Acceptance criteria

Requirement: Refuse UV_PYTHON override

build_subprocess_env SHALL raise SecurityError when a caller override sets UV_PYTHON.

Scenario: Caller sets UV_PYTHON

  • WHEN build_subprocess_env is called with env containing UV_PYTHON
  • THEN SecurityError is raised with the key name in the message

Requirement: Refuse npm_config_script_shell override

build_subprocess_env SHALL raise SecurityError when a caller override sets npm_config_script_shell.

Scenario: Caller sets npm_config_script_shell

  • WHEN build_subprocess_env is called with env containing npm_config_script_shell
  • THEN SecurityError is raised with the key name in the message

Requirement: Refuse npm_config_node_options override

build_subprocess_env SHALL raise SecurityError when a caller override sets npm_config_node_options.

Scenario: Caller sets npm_config_node_options

  • WHEN build_subprocess_env is called with env containing npm_config_node_options
  • THEN SecurityError is raised with the key name in the message

Requirement: Refuse VIRTUAL_ENV override

build_subprocess_env SHALL raise SecurityError when a caller override sets VIRTUAL_ENV.

Scenario: Caller sets VIRTUAL_ENV

  • WHEN build_subprocess_env is called with env containing VIRTUAL_ENV
  • THEN SecurityError is raised with the key name in the message

Requirement: Refuse GOFLAGS override

build_subprocess_env SHALL raise SecurityError when a caller override sets GOFLAGS.

Scenario: Caller sets GOFLAGS

  • WHEN build_subprocess_env is called with env containing GOFLAGS
  • THEN SecurityError is raised with the key name in the message

Requirement: Block UV_PYTHON from ambient environment

An isolated child SHALL NOT receive UV_PYTHON from the ambient environment.

Scenario: UV_PYTHON in ambient environment

  • WHEN build_subprocess_env is called with isolate_env=True and UV_PYTHON is in os.environ
  • THEN UV_PYTHON is not in the returned dict

Requirement: Remove VIRTUAL_ENV from allowlist

VIRTUAL_ENV SHALL NOT be in DEFAULT_ALLOWED_ENV_VARS.

Scenario: VIRTUAL_ENV in ambient environment

  • WHEN build_subprocess_env is called with isolate_env=True and VIRTUAL_ENV is in os.environ
  • THEN VIRTUAL_ENV is not in the returned dict

Requirement: Accept legitimate npm_config keys

build_subprocess_env SHALL accept npm_config_cache, npm_config_userconfig, npm_config_globalconfig, npm_config_update_notifier, and npm_config_loglevel as caller overrides.

Scenario: Caller sets legitimate npm_config keys

  • WHEN build_subprocess_env is called with env containing npm_config_cache
  • THEN No SecurityError is raised and the key is in the returned dict

Existing Tool Considered

No open, maintained tool or library covers this need. The project builds its own guard. The written cost is about 15 lines of code (one new constant, one function update, one allowlist edit) and about 40 lines of tests, roughly 600 tokens to build. The ongoing cost is about 2 lines per key added to the list.

Key questions

  • Which specific keys make a tool start a caller-named program?: UV_PYTHON, NPM_CONFIG_SCRIPT_SHELL, NPM_CONFIG_NODE_OPTIONS, GOFLAGS, and VIRTUAL_ENV. UV_PYTHON names the interpreter uv starts. NPM_CONFIG_SCRIPT_SHELL names the shell npm starts for scripts. NPM_CONFIG_NODE_OPTIONS passes options to node. GOFLAGS can carry -toolexec. VIRTUAL_ENV names the venv whose bin/python uv starts. [sources: src/devops_cli/core/process.py, src/devops_cli/commands/install_tools.py]
  • Should the new keys go in CONST_CODE_LOADING_ENV_PATTERNS or a new constant?: A new constant, because the category is different. CONST_CODE_LOADING_ENV_PATTERNS covers keys that make a child load code (libraries, modules). The new keys make a tool start a program. A separate constant keeps the two categories distinct and lets the guard name each key with its source. (best practice) [sources: src/devops_cli/config/constants.py, openspec/changes/archive/2026-10-28-2205-refuse-code-loading-env-keys/design.md]
    • Rejected: Extend CONST_CODE_LOADING_ENV_PATTERNS. Rejected. The existing constant is named for code-loading keys. Adding program-execution keys conflates two categories and makes the constant harder to maintain.
    • Chosen: New constant CONST_PROGRAM_EXEC_ENV_PATTERNS. Chosen. The category is different. A separate constant keeps the two concerns distinct and follows the pattern of one constant per category that the project already uses.
  • Should VIRTUAL_ENV be removed from DEFAULT_ALLOWED_ENV_VARS?: Yes. VIRTUAL_ENV names the venv whose bin/python uv starts. A caller that sets it gives a directory that it controls. The reply confirms that uv starts the bin/python of the environment the key names. (best practice) [sources: src/devops_cli/core/process.py]
    • Rejected: Keep VIRTUAL_ENV in the allowlist. Rejected. The key makes uv start a caller-named program. Keeping it in the allowlist leaves the defect open.
    • Chosen: Remove VIRTUAL_ENV from the allowlist and add it to the refused patterns. Chosen. The key is dangerous. Removing it from the allowlist stops the ambient path, and adding it to the refused patterns stops the caller override path.
  • Should the UV_ prefix be removed from DEFAULT_ALLOWED_ENV_PREFIXES?: No. The prefix is there for legitimate keys such as UV_CACHE_DIR, UV_LINK_MODE, and UV_MALWARE_CHECK. Only UV_PYTHON is dangerous. Refuse UV_PYTHON specifically and keep the prefix. (best practice) [sources: src/devops_cli/commands/install_tools.py]
    • Rejected: Remove the UV_ prefix. Rejected. It breaks UV_CACHE_DIR, UV_LINK_MODE, and UV_MALWARE_CHECK, which install_tools.py sets as caller overrides.
    • Chosen: Keep the UV_ prefix and refuse UV_PYTHON specifically. Chosen. The prefix covers legitimate keys. Only UV_PYTHON is dangerous. A specific key name is the smallest change that closes the defect.
  • Should npm_config_ be refused as a family pattern?*: No. install_tools.py sets npm_config_cache, npm_config_userconfig, npm_config_globalconfig, npm_config_update_notifier, and npm_config_loglevel as caller overrides. A family pattern would break these. Refuse only npm_config_script_shell and npm_config_node_options by name. (best practice) [sources: src/devops_cli/commands/install_tools.py]
    • Rejected: Refuse the npm_config_* family. Rejected. It breaks the legitimate keys that install_tools.py sets as caller overrides.
    • Chosen: Refuse npm_config_script_shell and npm_config_node_options by name. Chosen. These two keys make npm start a caller-named program. The other npm_config_* keys in install_tools.py do not.
  • Should the new keys be denied in the ambient environment filter, not just the caller override check?: Yes. UV_PYTHON reaches an isolated child from the ambient environment through the UV_ prefix. VIRTUAL_ENV reaches it through DEFAULT_ALLOWED_ENV_VARS. The ambient filter must deny the new keys so they do not reach an isolated child. (best practice) [sources: src/devops_cli/core/process.py]
    • Rejected: Deny only in the caller override check. Rejected. UV_PYTHON and VIRTUAL_ENV reach an isolated child from the ambient environment. The caller override check does not cover this path.
    • Chosen: Deny in both the ambient filter and the caller override check. Chosen. Both paths must be closed. The ambient filter stops the key from reaching an isolated child. The caller override check stops a caller from setting it.

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. A security guard accepts keys that let a caller start an arbitrary program in a child process.
    • Priority: P1-High. A demonstrated path to arbitrary code execution in child processes is a high-severity security gap.
    • Value: High. Prevents arbitrary program execution in every uv, npm, and go child the CLI starts.
    • Effort: Medium. Must add specific key patterns while excluding legitimate npm_config_* keys the tool itself sets.
    • 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 harden build_subprocess_env against tool keys that make a child run a caller-named program, but #2483 targets git keys while the candidate targets uv, npm, and go keys.
  3. added
    priority/p1-high
    on Oct 29, 2026
  4. dan-petty commented on Oct 29, 2026

    @dan-petty
    OwnerAuthor

    VIRTUAL_ENV is a key of the same kind, and the guard accepts it. It is in DEFAULT_ALLOWED_ENV_VARS (src/devops_cli/core/process.py), so it also reaches an isolated child from the environment. uv starts the bin/python of the environment that the key names.

    Probe, with uv 0.12.23, in a temporary directory <dir> and a temporary HOME:

    1. Make <dir>/fake/bin/python and <dir>/fake/bin/python3. Each is an executable shell script that appends the line FAKE-VENV-PYTHON-RAN to <dir>/marker and then runs /usr/bin/python3 "$@". Add a pyvenv.cfg file to <dir>/fake.
    2. Run env -i PATH=/usr/local/bin:/usr/bin:/bin HOME=<home> UV_CACHE_DIR=<dir>/cache VIRTUAL_ENV=<dir>/fake uv --offline --no-config pip list.
    3. Read <dir>/marker. It holds FAKE-VENV-PYTHON-RAN.
    4. Run the same command with no VIRTUAL_ENV. The marker file is not created.

    The probe is the finding of a review of the change for #2503. This issue should decide VIRTUAL_ENV with UV_PYTHON, because a caller of a uv child sets or needs the key in the same way.

  5. added
    status/ready
    and removed
    status/new
    on Oct 29, 2026
  6. devops-cli-service commented on Oct 29, 2026

    @devops-cli-service
    Contributor

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

  7. added
    type/bug
    scope/security
    and removed
    type/security
    on Oct 30, 2026
  8. removed
    status/ready
    on Oct 30, 2026
  9. added a commit that references this issue 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