Repository navigation
Description
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_PYTHONnames the Python interpreter thatuv runstarts.uvstarts the program of the key to ask it for its version. The prefixUV_is inDEFAULT_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_shellnames the shell thatnpm runstarts for each script.npm_config_node_optionsandnpm_config_userconfigare keys of the same family.src/devops_cli/commands/install_tools.pysets othernpm_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
- 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")))'. - In a temporary directory
<dir>, write an executable<dir>/fake-pythonthat appends the lineFAKE-PYTHON-RANto<dir>/markerand then runs/usr/bin/python3 "$@". - In
<dir>, runenv -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. - In a second directory with a
package.jsonthat has the scriptt(echo hi), write an executablefake-shthat appendsFAKE-SH-RANto a marker and then runs/bin/sh "$@". Runenv -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-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.
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
dan-petty commentedon Oct 29, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
A security guard accepts keys that let a caller start an arbitrary program in a child process.A demonstrated path to arbitrary code execution in child processes is a high-severity security gap.Prevents arbitrary program execution in every uv, npm, and go child the CLI starts.Must add specific key patterns while excluding legitimate npm_config_* keys the tool itself sets.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.dan-petty commentedon Oct 29, 2026
VIRTUAL_ENVis a key of the same kind, and the guard accepts it. It is inDEFAULT_ALLOWED_ENV_VARS(src/devops_cli/core/process.py), so it also reaches an isolated child from the environment.uvstarts thebin/pythonof the environment that the key names.Probe, with uv 0.12.23, in a temporary directory
<dir>and a temporaryHOME:<dir>/fake/bin/pythonand<dir>/fake/bin/python3. Each is an executable shell script that appends the lineFAKE-VENV-PYTHON-RANto<dir>/markerand then runs/usr/bin/python3 "$@". Add apyvenv.cfgfile to<dir>/fake.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.<dir>/marker. It holdsFAKE-VENV-PYTHON-RAN.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_ENVwithUV_PYTHON, because a caller of auvchild sets or needs the key in the same way.fix(security): refuse the library keys that load a module (#2682)
devops-cli-service commentedon Oct 29, 2026
Status set to Ready at c462318 (see proposed design in issue body).
chore(main): release 0.22.0 (#2751)