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 glibc loader keys, every DYLD_ key and the bash start-up keys (#2205). It accepts other keys that make a child load or run code that its caller did not choose:
ZDOTDIR:zshreads$ZDOTDIR/.zshenvat each start, also forzsh -c. This is the zsh form ofBASH_ENV.- Interpreter keys:
PYTHONPATH(Python importssitecustomizefrom it at start),NODE_OPTIONS(--require <file>runs a file before the program), andPERL5OPTwithPERL5LIB(-M<module>loads a module from it). There are more keys of this kind, for examplePYTHONSTARTUP,PYTHONHOMEandRUBYOPT.
The design of #2205 recorded these keys as a non-goal, because #2205 asked only for the loader and bash families. It named no follow-up issue.
DEFAULT_ALLOWED_ENV_VARS in the same module lets the ambient PYTHONPATH and PYTHONHOME reach an isolated child. Thus the fix must decide which interpreter keys a caller or the person can set, and which the guard refuses.
Reproduction Steps
- Run
uv run python -c 'from devops_cli.core.process import build_subprocess_env as b; print(sorted(b(env={"ZDOTDIR": "x", "PYTHONPATH": "x", "NODE_OPTIONS": "x", "PERL5OPT": "x", "PERL5LIB": "x"})))'. - In a temporary directory
<dir>, write.zshenvthat prints a marker. Runenv -i PATH=/usr/bin:/bin ZDOTDIR=<dir> zsh -c true. - In
<dir>, writesitecustomize.pythat prints a marker. Runenv -i PATH=/usr/bin:/bin PYTHONPATH=<dir> python3 -c pass. - In
<dir>, writer.jsthat prints a marker. Runenv -i PATH=<node dir>:/usr/bin:/bin NODE_OPTIONS="--require <dir>/r.js" node -e 0.
Expected vs Actual Behavior
Expected: build_subprocess_env raises SecurityError for a caller override that makes the child shell or interpreter load or run code, or the design of the guard names each such key that it accepts and the reason.
Actual: step 1 returns all five keys with no SecurityError. Steps 2, 3 and 4 each print their marker, so the child runs code from <dir> before the requested command.
Environment Diagnostics
- DevOps CLI Version: main at d739a47 (after fix(security): refuse every loader and shell key that loads code into a child #2405)
- 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 ZDOTDIR=<dir> zsh -c true # zsh 5.9.2
ZDOTDIR-CODE-RAN
$ env -i PATH=/usr/bin:/bin PYTHONPATH=<dir> python3 -c pass # Python 3.14.10
PYTHONPATH-CODE-RAN
$ env -i PATH=<node dir>:/usr/bin:/bin NODE_OPTIONS="--require <dir>/r.js" node -e 0 # node v24.22.1
NODE-OPTIONS-CODE-RAN
$ env -i PATH=/usr/bin:/bin PERL5LIB=<dir>/pl PERL5OPT=-MX perl -e 1 # perl v5.42.3
PERL5OPT-CODE-RANThe review of PR #2405 found the ZDOTDIR case. The other keys are the non-goal of the #2205 design.
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: #2405
Proposed design
Problem statement
build_subprocess_env in src/devops_cli/core/process.py accepts caller overrides and ambient pass-through of environment keys that make a child shell or interpreter load or run code the caller did not choose. The current guard (CONST_CODE_LOADING_ENV_PATTERNS) covers only the glibc loader, macOS dyld, and bash families. Keys such as ZDOTDIR, PYTHONPATH, NODE_OPTIONS, PERL5OPT, PERL5LIB, PYTHONSTARTUP, PYTHONHOME, and RUBYOPT are not refused, and PYTHONPATH and PYTHONHOME are in DEFAULT_ALLOWED_ENV_VARS, so they reach isolated children from the ambient environment. This is a security defect: any caller can be tricked into running arbitrary code in the child process across five interpreters.
Acceptance criteria
- Criterion 1: build_subprocess_env raises SecurityError for a caller override key that is ZDOTDIR, PYTHONPATH, NODE_OPTIONS, PERL5OPT, PERL5LIB, PYTHONSTARTUP, PYTHONHOME, or RUBYOPT, case-insensitive.
Verification: Run: uv run python -c 'from devops_cli.core.process import build_subprocess_env as b; b(env={"ZDOTDIR": "x"})'. Expect SecurityError. Repeat for each of the other seven keys. - Criterion 2: DEFAULT_ALLOWED_ENV_VARS does not include PYTHONPATH or PYTHONHOME.
Verification: Run: uv run python -c 'from devops_cli.core.process import DEFAULT_ALLOWED_ENV_VARS as d; assert "PYTHONPATH" not in d; assert "PYTHONHOME" not in d'. Expect no AssertionError. - Criterion 3: The existing refused keys (LD_AUDIT, LD_LIBRARY_PATH, LD_ORIGIN_PATH, LD_PRELOAD, DYLD_, BASH_ENV, ENV, BASH_FUNC_) still raise SecurityError for caller overrides.
Verification: Run the existing test suite for build_subprocess_env code-loading refusal. All tests pass. - Criterion 4: Tests cover each new refused key and verify SecurityError is raised with the expected message.
Verification: Run: uv run pytest tests/ -k 'code_loading' -v. All new tests pass. - Criterion 5: The guard refuses the new keys with both isolate_env=True and isolate_env=False.
Verification: Run: uv run python -c 'from devops_cli.core.process import build_subprocess_env as b; b(env={"NODE_OPTIONS": "--require /tmp/x.js"}, isolate_env=False)'. Expect SecurityError.
Key questions
- Which environment variable keys make a child shell or interpreter load or run code the caller did not choose?: ZDOTDIR (zsh reads $ZDOTDIR/.zshenv at each start, including zsh -c), PYTHONPATH (Python imports sitecustomize from it at start), NODE_OPTIONS (--require runs a file before the program), PERL5OPT with PERL5LIB (-M loads a module from it), PYTHONSTARTUP (Python reads a startup file), PYTHONHOME (Python uses it to locate its install, which can redirect imports), and RUBYOPT (Ruby reads options from it, including -r to require a file). [sources: src/devops_cli/core/process.py:61]
- Should all named code-loading keys be refused by the guard, or only a subset?: All named keys are refused. Each one makes a child load or run code the caller did not choose. The guard refuses them with SecurityError, the same as the existing loader and bash keys. (proposed)
- Should PYTHONPATH and PYTHONHOME be removed from DEFAULT_ALLOWED_ENV_VARS?: Yes. They allow an ambient path to reach an isolated child and let it load code, which is the same defect as a caller override. Removing them from the allowed set closes the ambient pass-through path. (proposed) [sources: src/devops_cli/core/process.py:61]
- Should the new patterns be added to the existing CONST_CODE_LOADING_ENV_PATTERNS constant?: Yes. The constant already holds the refused key families as fnmatch patterns, and build_subprocess_env already matches caller overrides against it via _is_env_var_denied. Adding the new keys there keeps one rule for all code-loading refusal. (proposed) [sources: src/devops_cli/config/constants.py:1587, src/devops_cli/core/process.py:130]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsReady
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 on the board.
The guard accepts environment keys that let a child process load or run code the caller did not choose, which is a security defect.Multiple interpreters (zsh, Python, Node, Perl, Ruby) can execute attacker-chosen code through accepted environment keys.Any caller of build_subprocess_env can be tricked into running arbitrary code in the child process across five interpreters.The fix requires choosing which keys to block, updating the pattern list, adjusting DEFAULT_ALLOWED_ENV_VARS, and adding tests for each interpreter.Both extend build_subprocess_env in the same file to refuse code-loading keys, but #2205 covers loader and bash keys while this candidate covers zsh and interpreter keys.dan-petty commentedon Oct 28, 2026
Status set to Ready at 19412fa (see proposed design in issue body).
fix(security): refuse GCONV_PATH, SHELLOPTS, BASHOPTS and PS4 from a …