Skip to content

fix(security): the subprocess environment guard accepts the pytest and npm keys that make a child write a file #2747

Closed

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. #2674 (pull request #2746) adds the keys that make curl, git, Python, Node.js and the glibc loader write a file that the caller names. The guard accepts more keys of the same kind in two other tools. A review of #2674 probed them with the real tools:

  • PYTEST_ADDOPTS with the value --junitxml=<path>: pytest 9.1.1 wrote a JUnit file at the path. The key gives pytest any option, so it can also make pytest write other files or load a plug-in with -p.
  • npm_config_logs_dir: npm wrote a debug log into the directory that the key names, when it ran npm ls.
  • npm_config_cache: npm wrote a cache file into the directory that the key names, when it ran npm ls.

These keys belong with the keys of #2674 (keys that write a file) and with the keys of #2673 (the uv and npm keys that run a program). npm_config_* is a family: npm reads each npm setting from a key with this prefix, so the fix has to decide between the family and the single keys.

Not claimed: the reviewer did not reproduce GNUTLS_KEYLOGFILE, PERLIO_DEBUG, MALLOC_TRACE or LOCPATH. No probe ran for ruby, go, java, dotnet or cargo. The fix issue must probe each key it claims.

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={"PYTEST_ADDOPTS": "x", "npm_config_logs_dir": "x", "npm_config_cache": "x"}) if k in ("PYTEST_ADDOPTS", "npm_config_logs_dir", "npm_config_cache")))'.
  2. In a temporary directory <dir>, run env -i PATH=<path> HOME=<dir> PYTEST_ADDOPTS=--junitxml=<dir>/junit.xml pytest <a test file in <dir>>. Read <dir>/junit.xml.
  3. Run env -i PATH=<path> HOME=<dir> npm_config_logs_dir=<dir>/logs npm_config_cache=<dir>/cache npm ls in a directory with a package.json. List <dir>/logs and <dir>/cache.

Expected vs Actual Behavior

Expected: build_subprocess_env raises SecurityError for a caller override of a key that makes a child write a file 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 three keys with no SecurityError. Steps 2 and 3 show the files that the keys name.

Environment Diagnostics

Pre-Submission Checklist

Proposed design

Problem statement

The subprocess environment guard in build_subprocess_env accepts three caller-provided keys that make a child process write a file the caller names. PYTEST_ADDOPTS lets pytest write a JUnit file or load a plugin. npm_config_logs_dir and npm_config_cache let npm write a log or a cache file. The guard must refuse these keys, as it already refuses the keys of #2674.

Acceptance criteria

Requirement: Refuse PYTEST_ADDOPTS override

build_subprocess_env SHALL raise SecurityError when a caller override sets PYTEST_ADDOPTS.

Scenario: Caller sets PYTEST_ADDOPTS

  • WHEN A caller passes PYTEST_ADDOPTS in the env dict to build_subprocess_env
  • THEN build_subprocess_env raises SecurityError

Requirement: Refuse npm_config family overrides

build_subprocess_env SHALL raise SecurityError when a caller override sets any key matching the npm_config_* family.

Scenario: Caller sets npm_config_logs_dir

  • WHEN A caller passes npm_config_logs_dir in the env dict to build_subprocess_env
  • THEN build_subprocess_env raises SecurityError

Requirement: Existing refusals unchanged

build_subprocess_env SHALL continue to raise SecurityError for every key already in CONST_CODE_LOADING_ENV_PATTERNS.

Scenario: Caller sets LD_PRELOAD

  • WHEN A caller passes LD_PRELOAD in the env dict to build_subprocess_env
  • THEN build_subprocess_env raises SecurityError

Existing Tool Considered

No check has run. No open, maintained tool or library covers this need. The project builds its own guard in src/devops_cli/core/process.py. The written cost is 3 pattern entries and a comment in src/devops_cli/config/constants.py, plus 6 test cases in tests/test_subprocess_env_boundary.py. The cost to keep and fix is zero: the patterns are static and no update is needed until a new tool is added. The elapsed time to build is under 10 minutes.

Key questions

  • Does the npm fix deny the npm_config_ family or only the two probed keys?*: Deny the family with the pattern NPM_CONFIG_. The existing guard already uses family patterns for dangerous families: DYLD_ and BASH_FUNC_*. The issue states that npm reads each npm setting from a key with this prefix, so any member of the family can direct a file write. A single-key list would miss future or unprobed members. (best practice) [sources: src/devops_cli/core/process.py, openspec/changes/archive/2026-10-28-2205-refuse-code-loading-env-keys/design.md]
    • Chosen: Deny the NPM_CONFIG_* family. Consistent with the existing DYLD_* and BASH_FUNC_* family patterns. npm reads every setting from a key with this prefix, so any member can direct a file write. A single-key list would miss unprobed members.
    • Rejected: Deny only npm_config_logs_dir and npm_config_cache. Narrower scope, but npm's config system is open-ended. A future or unprobed npm_config_* key could also direct a file write. The existing design uses family patterns for this case.
  • Is PYTEST_ADDOPTS a code-loading key, a file-writing key, or both?: Both. The value --junitxml= makes pytest write a JUnit file. The value -p makes pytest load a plugin, which runs code. The guard refuses it under the same constant as the other keys. [sources: src/devops_cli/core/process.py]
  • Must the fix probe each key it claims before adding it to the guard?: Yes. The issue states: 'The fix issue must probe each key it claims.' The reviewer probed PYTEST_ADDOPTS, npm_config_logs_dir and npm_config_cache with the real tools. The implementation must include a probe for each key it adds. [sources: src/devops_cli/core/process.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#2674

Activity

  1. added
    source/agent
    type/bug
    scope/security
    status/new
    value/high
    effort/medium
    on Oct 30, 2026
  2. dan-petty commented on Oct 30, 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/bug. The fix prefix of the title gives the type.
    • Scope: scope/security. The (security) scope of the title gives the scope.
    • Priority: P1-High. A caller can make a child write files to arbitrary paths, which is a real security gap.
    • Value: High. Closing the gap prevents unauthorized file writes in spawned child processes.
    • Effort: Medium. The fix must probe each key and decide the npm_config_* family scope, not just add three names.
    • Related: fix(security): the subprocess environment guard accepts the keys that make a child write TLS secrets or a log to a file that the caller names #2674, which asks for a different change. Both target the same guard in build_subprocess_env for keys that make a child write a file, but they name different keys and different tools.
  3. added
    priority/p1-high
    on Oct 30, 2026
  4. added
    status/ready
    and removed
    status/new
    on Oct 30, 2026
  5. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

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

  6. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

    The stage job stopped. The inputs of the step of the task group "Add PYTEST_ADDOPTS to the subprocess environment guard" hold 48286 tokens, over the budget of 40000 tokens, also after the model split the groups once. A person decides how to split the item. The job stages the item again when a person runs it with --item 2747.

    The task groups:

    1. Add PYTEST_ADDOPTS to the subprocess environment guard: 48286 tokens
    2. Add NPM_CONFIG_* to the subprocess environment guard: 48300 tokens
  7. devops-cli-service commented on Oct 31, 2026

    @devops-cli-service
    Contributor

    Staged: branch fix/2747-the-subprocess-environment-guard-accepts-the, draft pull request #2870. The pull request plans the item and closes no issue.

    The task groups, with the tokens of the inputs of each step, for a budget of 40000 tokens:

    1. Add PYTEST_ADDOPTS and NPM_CONFIG_* to the guard: 3728 tokens
  8. added a commit that references this issue on Oct 31, 2026
  9. 6 remaining items

  10. added
    status/planned
    on Oct 31, 2026
  11. added
    status/blocked
    and removed
    status/planned
    on Nov 1, 2026
  12. added
    owner/agent
    on Nov 1, 2026
  13. added a commit that references this issue on Nov 1, 2026
  14. removed
    owner/agent
    on Nov 1, 2026
  15. dan-petty commented on Nov 1, 2026

    @dan-petty
    OwnerAuthor

    implement: retry

  16. added
    status/planned
    and removed
    status/blocked
    on Nov 1, 2026
  17. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    Cleared the stop at group 1 by the rule retry: a person commented implement: retry. The item is Planned again, and the Service takes it in the next round.

  18. removed
    status/planned
    on Nov 1, 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