Skip to content

fix(security): the subprocess environment guard refuses the zsh and interpreter keys that make a child run code #2429

Closed

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 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: zsh reads $ZDOTDIR/.zshenv at each start, also for zsh -c. This is the zsh form of BASH_ENV.
  • Interpreter keys: PYTHONPATH (Python imports sitecustomize from it at start), NODE_OPTIONS (--require <file> runs a file before the program), and PERL5OPT with PERL5LIB (-M<module> loads a module from it). There are more keys of this kind, for example PYTHONSTARTUP, PYTHONHOME and RUBYOPT.

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

  1. 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"})))'.
  2. In a temporary directory <dir>, write .zshenv that prints a marker. Run env -i PATH=/usr/bin:/bin ZDOTDIR=<dir> zsh -c true.
  3. In <dir>, write sitecustomize.py that prints a marker. Run env -i PATH=/usr/bin:/bin PYTHONPATH=<dir> python3 -c pass.
  4. In <dir>, write r.js that prints a marker. Run env -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

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

The 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.

Activity

  1. added
    source/agent
    type/security
    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 on the board.

    • Type: type/security. The guard accepts environment keys that let a child process load or run code the caller did not choose, which is a security defect.
    • Priority: P1-High. Multiple interpreters (zsh, Python, Node, Perl, Ruby) can execute attacker-chosen code through accepted environment keys.
    • Value: High. Any caller of build_subprocess_env can be tricked into running arbitrary code in the child process across five interpreters.
    • Effort: Medium. The fix requires choosing which keys to block, updating the pattern list, adjusting DEFAULT_ALLOWED_ENV_VARS, and adding tests for each interpreter.
    • Related: fix(security): the subprocess environment guard refuses ld_audit, every dyld_ key and exported bash functions #2205, which asks for a different change. 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.
  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

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

  4. added
    priority/p1-high
    status/ready
    effort/medium
    value/high
    on Oct 28, 2026
  5. 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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions